From b3021dc88dc5063f2c7a6b6f5cd7327b8e09ee93 Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Wed, 11 Nov 2015 14:37:11 -0500 Subject: [PATCH 1/2] Better test for isarray in figaspect(). Closes #5464. --- lib/matplotlib/figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index b640fed01317..e716f08ccdd0 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1758,7 +1758,7 @@ def figaspect(arg): Thanks to Fernando Perez for this function """ - isarray = hasattr(arg, 'shape') + isarray = not np.isscalar(arg) # min/max sizes to respect when autoscaling. If John likes the idea, they # could become rc parameters, for now they're hardwired. From 47fb83ab68f85933043705ac2bea2e1a0b1b55ff Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Thu, 12 Nov 2015 16:33:26 -0500 Subject: [PATCH 2/2] Added the old test back in to prevent error handling change. Also unit test! --- lib/matplotlib/figure.py | 2 +- lib/matplotlib/tests/test_figure.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index e716f08ccdd0..0de748cf7a78 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1758,7 +1758,7 @@ def figaspect(arg): Thanks to Fernando Perez for this function """ - isarray = not np.isscalar(arg) + isarray = hasattr(arg, 'shape') and not np.isscalar(arg) # min/max sizes to respect when autoscaling. If John likes the idea, they # could become rc parameters, for now they're hardwired. diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 37f4b1ba62c1..631474c23287 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -8,6 +8,7 @@ from matplotlib.testing.decorators import image_comparison, cleanup from matplotlib.axes import Axes import matplotlib.pyplot as plt +import numpy as np @cleanup @@ -191,6 +192,17 @@ def test_axes_remove(): assert_equal(len(fig.axes), 3) +def test_figaspect(): + w, h = plt.figaspect(np.float64(2) / np.float64(1)) + assert h / w == 2 + w, h = plt.figaspect(2) + assert h / w == 2 + w, h = plt.figaspect(np.zeros((1, 2))) + assert h / w == 0.5 + w, h = plt.figaspect(np.zeros((2, 2))) + assert h / w == 1 + + if __name__ == "__main__": import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)