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

Skip to content

Commit deeec9c

Browse files
committed
Merge remote-tracking branch 'upstream/v1.5.x' into v2.0.x
2 parents ac7bba9 + 3909c5b commit deeec9c

File tree

5 files changed

+52
-40
lines changed

5 files changed

+52
-40
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/testing/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from contextlib import contextmanager
66

77
from matplotlib.cbook import is_string_like, iterable
8+
from matplotlib import rcParams, rcdefaults, use
89

910

1011
def _is_list_like(obj):
@@ -70,3 +71,36 @@ def assert_produces_warning(expected_warning=Warning, filter_level="always",
7071
% expected_warning.__name__)
7172
assert not extra_warnings, ("Caused unexpected warning(s): %r."
7273
% extra_warnings)
74+
75+
76+
def set_font_settings_for_testing():
77+
rcParams['font.family'] = 'DejaVu Sans'
78+
rcParams['text.hinting'] = False
79+
rcParams['text.hinting_factor'] = 8
80+
81+
82+
def setup():
83+
# The baseline images are created in this locale, so we should use
84+
# it during all of the tests.
85+
import locale
86+
import warnings
87+
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
88+
89+
try:
90+
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
91+
except locale.Error:
92+
try:
93+
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
94+
except locale.Error:
95+
warnings.warn(
96+
"Could not set locale to English/United States. "
97+
"Some date-related tests may fail")
98+
99+
use('Agg', warn=False) # use Agg backend for these tests
100+
101+
# These settings *must* be hardcoded for running the comparison
102+
# tests and are not necessarily the default values as specified in
103+
# rcsetup.py
104+
rcdefaults() # Start with all defaults
105+
106+
set_font_settings_for_testing()

lib/matplotlib/testing/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import matplotlib as mpl
1818
import matplotlib.style
19-
import matplotlib.tests
2019
import matplotlib.units
20+
import matplotlib.testing
2121
from matplotlib import cbook
2222
from matplotlib import ticker
2323
from matplotlib import pyplot as plt
@@ -85,7 +85,7 @@ class CleanupTest(object):
8585
def setup_class(cls):
8686
cls.original_units_registry = matplotlib.units.registry.copy()
8787
cls.original_settings = mpl.rcParams.copy()
88-
matplotlib.tests.setup()
88+
matplotlib.testing.setup()
8989

9090
@classmethod
9191
def teardown_class(cls):
@@ -175,7 +175,7 @@ def setup_class(cls):
175175
mpl.rcParams.update(cls._initial_settings)
176176
raise
177177
cls.original_settings = cls._initial_settings
178-
matplotlib.tests.set_font_settings_for_testing()
178+
matplotlib.testing.set_font_settings_for_testing()
179179
cls._func()
180180

181181
@classmethod
@@ -396,7 +396,7 @@ def switch_backend_decorator(func):
396396
def backend_switcher(*args, **kwargs):
397397
try:
398398
prev_backend = mpl.get_backend()
399-
matplotlib.tests.setup()
399+
matplotlib.testing.setup()
400400
plt.switch_backend(backend)
401401
result = func(*args, **kwargs)
402402
finally:

lib/matplotlib/tests/__init__.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import difflib
77
import os
88

9-
from matplotlib import rcParams, rcdefaults, use
10-
9+
from matplotlib.testing import setup
1110

1211
_multiprocess_can_split_ = True
1312

@@ -22,39 +21,6 @@
2221
'test data.')
2322

2423

25-
def set_font_settings_for_testing():
26-
rcParams['font.family'] = 'DejaVu Sans'
27-
rcParams['text.hinting'] = False
28-
rcParams['text.hinting_factor'] = 8
29-
30-
31-
def setup():
32-
# The baseline images are created in this locale, so we should use
33-
# it during all of the tests.
34-
import locale
35-
import warnings
36-
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
37-
38-
try:
39-
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
40-
except locale.Error:
41-
try:
42-
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
43-
except locale.Error:
44-
warnings.warn(
45-
"Could not set locale to English/United States. "
46-
"Some date-related tests may fail")
47-
48-
use('Agg', warn=False) # use Agg backend for these tests
49-
50-
# These settings *must* be hardcoded for running the comparison
51-
# tests and are not necessarily the default values as specified in
52-
# rcsetup.py
53-
rcdefaults() # Start with all defaults
54-
55-
set_font_settings_for_testing()
56-
57-
5824
def assert_str_equal(reference_str, test_str,
5925
format_str=('String {str1} and {str2} do not '
6026
'match:\n{differences}')):

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)