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

Skip to content

Commit 0ce413f

Browse files
authored
Merge pull request #7857 from QuLogic/deprecations
Fix/hide some deprecations
2 parents 91e7425 + e214769 commit 0ce413f

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

examples/api/custom_projection_example.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ def set_longitude_grid(self, degrees):
297297
class -- it provides a more convenient interface to set the
298298
ticking than set_xticks would.
299299
"""
300-
number = (360.0 / degrees) + 1
301-
self.xaxis.set_major_locator(
302-
FixedLocator(
303-
np.linspace(-np.pi, np.pi, number, True)[1:-1]))
300+
# Skip -180 and 180, which are the fixed limits.
301+
grid = np.arange(-180 + degrees, 180, degrees)
302+
self.xaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
304303
self.xaxis.set_major_formatter(self.ThetaFormatter(degrees))
305304

306305
def set_latitude_grid(self, degrees):
@@ -311,10 +310,9 @@ def set_latitude_grid(self, degrees):
311310
class -- it provides a more convenient interface than
312311
set_yticks would.
313312
"""
314-
number = (180.0 / degrees) + 1
315-
self.yaxis.set_major_locator(
316-
FixedLocator(
317-
np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1]))
313+
# Skip -90 and 90, which are the fixed limits.
314+
grid = np.arange(-90 + degrees, 90, degrees)
315+
self.yaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
318316
self.yaxis.set_major_formatter(self.ThetaFormatter(degrees))
319317

320318
def set_longitude_grid_ends(self, degrees):

lib/matplotlib/cm.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import six
1111

1212
import os
13-
import warnings as _warnings # To remove once spectral is removed
1413
import numpy as np
1514
from numpy import ma
1615
import matplotlib as mpl
@@ -69,7 +68,8 @@ def _generate_cmap(name, lutsize):
6968
"""Generates the requested cmap from its *name*. The lut size is
7069
*lutsize*."""
7170

72-
spec = datad[name]
71+
# Use superclass method to avoid deprecation warnings during initial load.
72+
spec = dict.__getitem__(datad, name)
7373

7474
# Generate the colormap object.
7575
if 'red' in spec:
@@ -81,19 +81,15 @@ def _generate_cmap(name, lutsize):
8181

8282
LUTSIZE = mpl.rcParams['image.lut']
8383

84-
# We silence warnings here to avoid raising the deprecation warning for
85-
# spectral/spectral_r when this module is imported.
86-
with _warnings.catch_warnings():
87-
_warnings.simplefilter("ignore")
88-
# Generate the reversed specifications (all at once, to avoid
89-
# modify-when-iterating).
90-
datad.update({cmapname + '_r': _reverse_cmap_spec(spec)
91-
for cmapname, spec in six.iteritems(datad)})
92-
93-
# Precache the cmaps with ``lutsize = LUTSIZE``.
94-
# Also add the reversed ones added in the section above:
95-
for cmapname in datad:
96-
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
84+
# Generate the reversed specifications (all at once, to avoid
85+
# modify-when-iterating).
86+
datad.update({cmapname + '_r': _reverse_cmap_spec(spec)
87+
for cmapname, spec in six.iteritems(datad)})
88+
89+
# Precache the cmaps with ``lutsize = LUTSIZE``.
90+
# Also add the reversed ones added in the section above:
91+
for cmapname in datad:
92+
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
9793

9894
cmap_d.update(cmaps_listed)
9995

lib/matplotlib/projections/geo.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,18 @@ def set_longitude_grid(self, degrees):
190190
"""
191191
Set the number of degrees between each longitude grid.
192192
"""
193-
number = (360.0 / degrees) + 1
194-
self.xaxis.set_major_locator(
195-
FixedLocator(
196-
np.linspace(-np.pi, np.pi, number, True)[1:-1]))
193+
# Skip -180 and 180, which are the fixed limits.
194+
grid = np.arange(-180 + degrees, 180, degrees)
195+
self.xaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
197196
self.xaxis.set_major_formatter(self.ThetaFormatter(degrees))
198197

199198
def set_latitude_grid(self, degrees):
200199
"""
201-
Set the number of degrees between each longitude grid.
200+
Set the number of degrees between each latitude grid.
202201
"""
203-
number = (180.0 / degrees) + 1
204-
self.yaxis.set_major_locator(
205-
FixedLocator(
206-
np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1]))
202+
# Skip -90 and 90, which are the fixed limits.
203+
grid = np.arange(-90 + degrees, 90, degrees)
204+
self.yaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
207205
self.yaxis.set_major_formatter(self.ThetaFormatter(degrees))
208206

209207
def set_longitude_grid_ends(self, degrees):

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def convert(filename, cache):
217217
verifiers = {}
218218

219219
# Turning this off, because it seems to cause multiprocessing issues
220-
if matplotlib.checkdep_xmllint() and False:
220+
if False and matplotlib.checkdep_xmllint():
221221
verifiers['svg'] = lambda filename: [
222222
'xmllint', '--valid', '--nowarning', '--noout', filename]
223223

lib/matplotlib/tests/test_colors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
import six
55
import itertools
6-
import pytest
6+
import warnings
77
from distutils.version import LooseVersion as V
88

99
import numpy as np
10+
import pytest
1011

1112
from numpy.testing import assert_equal
1213
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
@@ -611,7 +612,10 @@ def test_colormap_reversing():
611612
"""Check the generated _lut data of a colormap and corresponding
612613
reversed colormap if they are almost the same."""
613614
for name in cm.cmap_d:
614-
cmap = plt.get_cmap(name)
615+
with warnings.catch_warnings(record=True) as w:
616+
warnings.simplefilter('always')
617+
cmap = plt.get_cmap(name)
618+
assert len(w) == (1 if name in ('spectral', 'spectral_r') else 0)
615619
cmap_r = cmap.reversed()
616620
if not cmap_r._isinit:
617621
cmap._init()

lib/matplotlib/tests/test_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_make_compound_path_empty():
9696
def test_xkcd():
9797
np.random.seed(0)
9898

99-
x = np.linspace(0, 2.0 * np.pi, 100.0)
99+
x = np.linspace(0, 2 * np.pi, 100)
100100
y = np.sin(x)
101101

102102
with plt.xkcd():

0 commit comments

Comments
 (0)