From 97e170d2fc2c2e8771148ea031bf39cdce3a014d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 7 Dec 2016 00:14:07 -0500 Subject: [PATCH 1/5] Pass integers to np.linspace/np.logspace's count. This fixes "DeprecationWarning: object of type cannot be safely interpreted as an integer." raised by latest NumPy. --- examples/api/custom_projection_example.py | 4 ++-- lib/matplotlib/projections/geo.py | 4 ++-- lib/matplotlib/tests/test_path.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/api/custom_projection_example.py b/examples/api/custom_projection_example.py index 7dc0ca2b1e41..b8c13eff733b 100644 --- a/examples/api/custom_projection_example.py +++ b/examples/api/custom_projection_example.py @@ -297,7 +297,7 @@ def set_longitude_grid(self, degrees): class -- it provides a more convenient interface to set the ticking than set_xticks would. """ - number = (360.0 / degrees) + 1 + number = int(360 / degrees) + 1 self.xaxis.set_major_locator( FixedLocator( np.linspace(-np.pi, np.pi, number, True)[1:-1])) @@ -311,7 +311,7 @@ def set_latitude_grid(self, degrees): class -- it provides a more convenient interface than set_yticks would. """ - number = (180.0 / degrees) + 1 + number = int(180 / degrees) + 1 self.yaxis.set_major_locator( FixedLocator( np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1])) diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index a428b1380cb6..e834f008795c 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -190,7 +190,7 @@ def set_longitude_grid(self, degrees): """ Set the number of degrees between each longitude grid. """ - number = (360.0 / degrees) + 1 + number = int(360 / degrees) + 1 self.xaxis.set_major_locator( FixedLocator( np.linspace(-np.pi, np.pi, number, True)[1:-1])) @@ -200,7 +200,7 @@ def set_latitude_grid(self, degrees): """ Set the number of degrees between each longitude grid. """ - number = (180.0 / degrees) + 1 + number = int(180 / degrees) + 1 self.yaxis.set_major_locator( FixedLocator( np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1])) diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index c29289ae81f2..71fcb7c89bc7 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -96,7 +96,7 @@ def test_make_compound_path_empty(): def test_xkcd(): np.random.seed(0) - x = np.linspace(0, 2.0 * np.pi, 100.0) + x = np.linspace(0, 2 * np.pi, 100) y = np.sin(x) with plt.xkcd(): From ffbc9bd91ee356fdb08e3fdb4edfbd7b3b328ed0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 16 Jan 2017 23:14:58 -0500 Subject: [PATCH 2/5] Catch warnings from deprecated colourmaps. --- lib/matplotlib/tests/test_colors.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index ca341e74cf42..7123beaa327f 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -3,10 +3,11 @@ import six import itertools -import pytest +import warnings from distutils.version import LooseVersion as V import numpy as np +import pytest from numpy.testing import assert_equal from numpy.testing.utils import assert_array_equal, assert_array_almost_equal @@ -612,7 +613,10 @@ def test_colormap_reversing(): """Check the generated _lut data of a colormap and corresponding reversed colormap if they are almost the same.""" for name in cm.cmap_d: - cmap = plt.get_cmap(name) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + cmap = plt.get_cmap(name) + assert len(w) == (1 if name in ('spectral', 'spectral_r') else 0) cmap_r = cmap.reversed() if not cmap_r._isinit: cmap._init() From dcaad03552d53e125282c9afbcc1c5a582789acf Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 16 Jan 2017 23:19:18 -0500 Subject: [PATCH 3/5] TST: Really avoid calling checkdep_xmllint in tests. --- lib/matplotlib/testing/compare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 122b6fd4a677..961d68cfe8df 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -211,7 +211,7 @@ def convert(filename, cache): verifiers = {} # Turning this off, because it seems to cause multiprocessing issues -if matplotlib.checkdep_xmllint() and False: +if False and matplotlib.checkdep_xmllint(): verifiers['svg'] = lambda filename: [ 'xmllint', '--valid', '--nowarning', '--noout', filename] From d6149e1870ea40c5ffabe715064e5046f83d3fc7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 20 Jan 2017 17:58:00 -0500 Subject: [PATCH 4/5] Make GeoAxes.set_{latitude,longitude}_grid clearer. Do the calculation in degrees instead of trying to "optimize" the calculation in radians. --- examples/api/custom_projection_example.py | 14 ++++++-------- lib/matplotlib/projections/geo.py | 16 +++++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/api/custom_projection_example.py b/examples/api/custom_projection_example.py index b8c13eff733b..1747027146ba 100644 --- a/examples/api/custom_projection_example.py +++ b/examples/api/custom_projection_example.py @@ -297,10 +297,9 @@ def set_longitude_grid(self, degrees): class -- it provides a more convenient interface to set the ticking than set_xticks would. """ - number = int(360 / degrees) + 1 - self.xaxis.set_major_locator( - FixedLocator( - np.linspace(-np.pi, np.pi, number, True)[1:-1])) + # Skip -180 and 180, which are the fixed limits. + grid = np.arange(-180 + degrees, 180, degrees) + self.xaxis.set_major_locator(FixedLocator(np.deg2rad(grid))) self.xaxis.set_major_formatter(self.ThetaFormatter(degrees)) def set_latitude_grid(self, degrees): @@ -311,10 +310,9 @@ def set_latitude_grid(self, degrees): class -- it provides a more convenient interface than set_yticks would. """ - number = int(180 / degrees) + 1 - self.yaxis.set_major_locator( - FixedLocator( - np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1])) + # Skip -90 and 90, which are the fixed limits. + grid = np.arange(-90 + degrees, 90, degrees) + self.yaxis.set_major_locator(FixedLocator(np.deg2rad(grid))) self.yaxis.set_major_formatter(self.ThetaFormatter(degrees)) def set_longitude_grid_ends(self, degrees): diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index e834f008795c..00071e6d05dc 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -190,20 +190,18 @@ def set_longitude_grid(self, degrees): """ Set the number of degrees between each longitude grid. """ - number = int(360 / degrees) + 1 - self.xaxis.set_major_locator( - FixedLocator( - np.linspace(-np.pi, np.pi, number, True)[1:-1])) + # Skip -180 and 180, which are the fixed limits. + grid = np.arange(-180 + degrees, 180, degrees) + self.xaxis.set_major_locator(FixedLocator(np.deg2rad(grid))) self.xaxis.set_major_formatter(self.ThetaFormatter(degrees)) def set_latitude_grid(self, degrees): """ - Set the number of degrees between each longitude grid. + Set the number of degrees between each latitude grid. """ - number = int(180 / degrees) + 1 - self.yaxis.set_major_locator( - FixedLocator( - np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1])) + # Skip -90 and 90, which are the fixed limits. + grid = np.arange(-90 + degrees, 90, degrees) + self.yaxis.set_major_locator(FixedLocator(np.deg2rad(grid))) self.yaxis.set_major_formatter(self.ThetaFormatter(degrees)) def set_longitude_grid_ends(self, degrees): From e2147691efaf52b4305ef537b0505b69754b68f1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 28 Jan 2017 05:03:53 -0500 Subject: [PATCH 5/5] Fix spectral/spectral_r deprecations on Python 2.7. In 2.7, the hidden __warningregistry__ gets set and then the warning is never seen again, regardless of the filter setting. Instead, just never trigger the warning in the first place (thanks @anntzer). --- lib/matplotlib/cm.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index adc2c14b824c..7e61585ead44 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -10,7 +10,6 @@ import six import os -import warnings as _warnings # To remove once spectral is removed import numpy as np from numpy import ma import matplotlib as mpl @@ -69,7 +68,8 @@ def _generate_cmap(name, lutsize): """Generates the requested cmap from its *name*. The lut size is *lutsize*.""" - spec = datad[name] + # Use superclass method to avoid deprecation warnings during initial load. + spec = dict.__getitem__(datad, name) # Generate the colormap object. if 'red' in spec: @@ -81,19 +81,15 @@ def _generate_cmap(name, lutsize): LUTSIZE = mpl.rcParams['image.lut'] -# We silence warnings here to avoid raising the deprecation warning for -# spectral/spectral_r when this module is imported. -with _warnings.catch_warnings(): - _warnings.simplefilter("ignore") - # Generate the reversed specifications (all at once, to avoid - # modify-when-iterating). - datad.update({cmapname + '_r': _reverse_cmap_spec(spec) - for cmapname, spec in six.iteritems(datad)}) - - # Precache the cmaps with ``lutsize = LUTSIZE``. - # Also add the reversed ones added in the section above: - for cmapname in datad: - cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE) +# Generate the reversed specifications (all at once, to avoid +# modify-when-iterating). +datad.update({cmapname + '_r': _reverse_cmap_spec(spec) + for cmapname, spec in six.iteritems(datad)}) + +# Precache the cmaps with ``lutsize = LUTSIZE``. +# Also add the reversed ones added in the section above: +for cmapname in datad: + cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE) cmap_d.update(cmaps_listed) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy