Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91ca2a3

Browse files
committed
Merge pull request #5465 from WeatherGod/fix_5464
FIX: Better test for isarray in figaspect(). Closes #5464.
2 parents 90678e4 + 47fb83a commit 91ca2a3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ def figaspect(arg):
17581758
Thanks to Fernando Perez for this function
17591759
"""
17601760

1761-
isarray = hasattr(arg, 'shape')
1761+
isarray = hasattr(arg, 'shape') and not np.isscalar(arg)
17621762

17631763
# min/max sizes to respect when autoscaling. If John likes the idea, they
17641764
# could become rc parameters, for now they're hardwired.

lib/matplotlib/tests/test_figure.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from matplotlib.testing.decorators import image_comparison, cleanup
99
from matplotlib.axes import Axes
1010
import matplotlib.pyplot as plt
11+
import numpy as np
1112

1213

1314
@cleanup
@@ -191,6 +192,17 @@ def test_axes_remove():
191192
assert_equal(len(fig.axes), 3)
192193

193194

195+
def test_figaspect():
196+
w, h = plt.figaspect(np.float64(2) / np.float64(1))
197+
assert h / w == 2
198+
w, h = plt.figaspect(2)
199+
assert h / w == 2
200+
w, h = plt.figaspect(np.zeros((1, 2)))
201+
assert h / w == 0.5
202+
w, h = plt.figaspect(np.zeros((2, 2)))
203+
assert h / w == 1
204+
205+
194206
if __name__ == "__main__":
195207
import nose
196208
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)