From 0d73999cfdfab8ce5f096d0964ee4025ba497641 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Dec 2015 12:37:24 -0600 Subject: [PATCH 1/5] Allow axes to be provided to imshow and fix colorbar Allow axes to be provided to imshow and fix colorbar Allow axes to be provided to imshow and fix colorbar Allow axes to be provided to imshow and fix colorbar Use tight layout by default Try and fix appveyor issue Handle deprecation warning on appveyor Pin the colorbar to the image using box-forced Fix tests again Update function signature Update function signature Fix imshow call Fix docstring with utf characters Remove kwargs --- .travis.yml | 8 +++++--- skimage/io/_plugins/matplotlib_plugin.py | 22 ++++++++++++++++------ skimage/io/tests/test_mpl_imshow.py | 5 +++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index d3c10f2c..a26d1af9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,8 @@ addons: packages: - ccache - libfreeimage3 - - texlive - - texlive-latex-extra + - texlive + - texlive-latex-extra - dvipng - python-qt4 env: @@ -53,7 +53,9 @@ before_install: install: - python setup.py develop -script: tools/travis_script.sh +script: + - tools/travis_script.sh + - grep -irn "R385" doc/build after_success: - coveralls diff --git a/skimage/io/_plugins/matplotlib_plugin.py b/skimage/io/_plugins/matplotlib_plugin.py index a9754a72..e958cc36 100644 --- a/skimage/io/_plugins/matplotlib_plugin.py +++ b/skimage/io/_plugins/matplotlib_plugin.py @@ -2,6 +2,7 @@ from collections import namedtuple import numpy as np import warnings import matplotlib.pyplot as plt +from mpl_toolkits.axes_grid1 import make_axes_locatable from ...util import dtype as dtypes from ...exposure import is_low_contrast from ...util.colormap import viridis @@ -110,7 +111,7 @@ def _get_display_range(image): return lo, hi, cmap -def imshow(im, *args, **kwargs): +def imshow(im, ax=None, show_cbar=None, **kwargs): """Show the input image and return the current axes. By default, the image is displayed in greyscale, rather than @@ -131,8 +132,11 @@ def imshow(im, *args, **kwargs): ---------- im : array, shape (M, N[, 3]) The image to display. - - *args, **kwargs : positional and keyword arguments + ax: `matplotlib.axes.Axes`, optional + The axis to use for the image, defaults to plt.gca(). + show_cbar: boolean, optional. + Whether to show the colorbar (used to override default behavior). + **kwargs : Keyword arguments These are passed directly to `matplotlib.pyplot.imshow`. Returns @@ -147,9 +151,15 @@ def imshow(im, *args, **kwargs): kwargs.setdefault('cmap', cmap) kwargs.setdefault('vmin', lo) kwargs.setdefault('vmax', hi) - ax_im = plt.imshow(im, *args, **kwargs) - if cmap != _default_colormap: - plt.colorbar() + + ax = ax or plt.gca() + ax_im = ax.imshow(im, **kwargs) + if (cmap != _default_colormap and show_cbar is not False) or show_cbar: + divider = make_axes_locatable(ax) + cax = divider.append_axes("right", size="5%", pad=0.05) + plt.colorbar(ax_im, cax=cax) + ax.set_adjustable('box-forced') + ax.get_figure().tight_layout() return ax_im imread = plt.imread diff --git a/skimage/io/tests/test_mpl_imshow.py b/skimage/io/tests/test_mpl_imshow.py index e369273a..26482f64 100644 --- a/skimage/io/tests/test_mpl_imshow.py +++ b/skimage/io/tests/test_mpl_imshow.py @@ -78,7 +78,7 @@ def test_low_dynamic_range(): def test_outside_standard_range(): plt.figure() - with expected_warnings(["out of standard range"]): + with expected_warnings(["out of standard range|CObject type is marked"]): ax_im = io.imshow(im_hi) assert ax_im.get_clim() == (im_hi.min(), im_hi.max()) assert n_subplots(ax_im) == 2 @@ -87,7 +87,8 @@ def test_outside_standard_range(): def test_nonstandard_type(): plt.figure() - with expected_warnings(["Low image dynamic range"]): + + with expected_warnings(["Low image dynamic range|CObject type is marked"]): ax_im = io.imshow(im64) assert ax_im.get_clim() == (im64.min(), im64.max()) assert n_subplots(ax_im) == 2 From b4793caebd7b47052329f72407673a6bb3922d33 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 25 Dec 2015 15:13:11 -0600 Subject: [PATCH 2/5] Remove debug message --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a26d1af9..7cc52075 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,9 +53,7 @@ before_install: install: - python setup.py develop -script: - - tools/travis_script.sh - - grep -irn "R385" doc/build +script: tools/travis_script.sh after_success: - coveralls From da038c4d88d23039516f9f1a9561862c4d6a4ac3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 31 Jan 2016 07:48:47 -0600 Subject: [PATCH 3/5] Debugging appveyor warning --- skimage/io/tests/test_mpl_imshow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/io/tests/test_mpl_imshow.py b/skimage/io/tests/test_mpl_imshow.py index 26482f64..19a3c52e 100644 --- a/skimage/io/tests/test_mpl_imshow.py +++ b/skimage/io/tests/test_mpl_imshow.py @@ -78,7 +78,7 @@ def test_low_dynamic_range(): def test_outside_standard_range(): plt.figure() - with expected_warnings(["out of standard range|CObject type is marked"]): + with expected_warnings(["out of standard range"]): ax_im = io.imshow(im_hi) assert ax_im.get_clim() == (im_hi.min(), im_hi.max()) assert n_subplots(ax_im) == 2 @@ -88,7 +88,7 @@ def test_outside_standard_range(): def test_nonstandard_type(): plt.figure() - with expected_warnings(["Low image dynamic range|CObject type is marked"]): + with expected_warnings(["Low image dynamic range"]): ax_im = io.imshow(im64) assert ax_im.get_clim() == (im64.min(), im64.max()) assert n_subplots(ax_im) == 2 From bbb35134a70e5474afb3629b0d5853dffe199279 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 31 Jan 2016 08:36:38 -0600 Subject: [PATCH 4/5] Add a note about the new warning --- skimage/io/tests/test_mpl_imshow.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/skimage/io/tests/test_mpl_imshow.py b/skimage/io/tests/test_mpl_imshow.py index 19a3c52e..6ebf800b 100644 --- a/skimage/io/tests/test_mpl_imshow.py +++ b/skimage/io/tests/test_mpl_imshow.py @@ -78,7 +78,10 @@ def test_low_dynamic_range(): def test_outside_standard_range(): plt.figure() - with expected_warnings(["out of standard range"]): + # Warning raised by matplotlib on Windows: + # "The CObject type is marked Pending Deprecation in Python 2.7. + # Please use capsule objects instead." + with expected_warnings(["out of standard range|CObject type is marked"]): ax_im = io.imshow(im_hi) assert ax_im.get_clim() == (im_hi.min(), im_hi.max()) assert n_subplots(ax_im) == 2 @@ -87,8 +90,10 @@ def test_outside_standard_range(): def test_nonstandard_type(): plt.figure() - - with expected_warnings(["Low image dynamic range"]): + # Warning raised by matplotlib on Windows: + # "The CObject type is marked Pending Deprecation in Python 2.7. + # Please use capsule objects instead." + with expected_warnings(["Low image dynamic range|CObject type is marked"]): ax_im = io.imshow(im64) assert ax_im.get_clim() == (im64.min(), im64.max()) assert n_subplots(ax_im) == 2 From 0aafbaf78bbc419e7c7a1b6eceeb9893e0cc4381 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 31 Jan 2016 08:37:49 -0600 Subject: [PATCH 5/5] Add another note about the new warning --- skimage/io/tests/test_mpl_imshow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skimage/io/tests/test_mpl_imshow.py b/skimage/io/tests/test_mpl_imshow.py index 6ebf800b..76422580 100644 --- a/skimage/io/tests/test_mpl_imshow.py +++ b/skimage/io/tests/test_mpl_imshow.py @@ -81,6 +81,7 @@ def test_outside_standard_range(): # Warning raised by matplotlib on Windows: # "The CObject type is marked Pending Deprecation in Python 2.7. # Please use capsule objects instead." + # Ref: https://docs.python.org/2/c-api/cobject.html with expected_warnings(["out of standard range|CObject type is marked"]): ax_im = io.imshow(im_hi) assert ax_im.get_clim() == (im_hi.min(), im_hi.max()) @@ -93,6 +94,7 @@ def test_nonstandard_type(): # Warning raised by matplotlib on Windows: # "The CObject type is marked Pending Deprecation in Python 2.7. # Please use capsule objects instead." + # Ref: https://docs.python.org/2/c-api/cobject.html with expected_warnings(["Low image dynamic range|CObject type is marked"]): ax_im = io.imshow(im64) assert ax_im.get_clim() == (im64.min(), im64.max())