From 7c8ed006b8fbcc8d1a5d14fcca6acea848889565 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Sun, 28 Dec 2014 12:19:56 +0100 Subject: [PATCH 1/6] Ignore NaN warnings in angle helper. It it expected that the array may contain nan and this is handled correctly using nanmin --- lib/mpl_toolkits/axisartist/angle_helper.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/mpl_toolkits/axisartist/angle_helper.py b/lib/mpl_toolkits/axisartist/angle_helper.py index a47aaeab81ed..feab84a6940a 100644 --- a/lib/mpl_toolkits/axisartist/angle_helper.py +++ b/lib/mpl_toolkits/axisartist/angle_helper.py @@ -386,12 +386,13 @@ def __call__(self, transform_xy, x1, y1, x2, y2): # iron out jumps, but algorithm should be improved. # Tis is just naive way of doing and my fail for some cases. - if self.lon_cycle is not None: - lon0 = np.nanmin(lon) - lon -= 360. * ((lon - lon0) > 180.) - if self.lat_cycle is not None: - lat0 = np.nanmin(lat) - lat -= 360. * ((lat - lat0) > 180.) + with np.errstate(invalid='ignore'): + if self.lon_cycle is not None: + lon0 = np.nanmin(lon) + lon -= 360. * ((lon - lon0) > 180.) + if self.lat_cycle is not None: + lat0 = np.nanmin(lat) + lat -= 360. * ((lat - lat0) > 180.) lon_min, lon_max = np.nanmin(lon), np.nanmax(lon) lat_min, lat_max = np.nanmin(lat), np.nanmax(lat) From bb2499cae1bab27d94b21c66066babc588476dd0 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Sun, 28 Dec 2014 13:56:31 +0100 Subject: [PATCH 2/6] Filter invalid warning in calculation of theta --- lib/matplotlib/projections/polar.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 5277d5ef9fa9..5e815a0654a6 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -146,7 +146,13 @@ def transform_non_affine(self, xy): x = xy[:, 0:1] y = xy[:, 1:] r = np.sqrt(x*x + y*y) - theta = np.arccos(x / r) + with np.errstate(invalid='ignore'): + # At x=y=r=0 this will raise an + # invalid value warning when doing 0/0 + # Divide by zero warnings are only raised when + # the numerator is different from 0. That + # should not happen here. + theta = np.arccos(x / r) theta = np.where(y < 0, 2 * np.pi - theta, theta) theta -= theta_offset From 8917da06c0a98a00e1c725456db390e90ccbf026 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Sun, 28 Dec 2014 14:20:10 +0100 Subject: [PATCH 3/6] Filter warning in tight layout demo: --- examples/pylab_examples/demo_tight_layout.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/pylab_examples/demo_tight_layout.py b/examples/pylab_examples/demo_tight_layout.py index 789dab3944ce..bcdeef3cc05a 100644 --- a/examples/pylab_examples/demo_tight_layout.py +++ b/examples/pylab_examples/demo_tight_layout.py @@ -1,6 +1,6 @@ import matplotlib.pyplot as plt - +import warnings import random fontsizes = [8, 16, 24, 32] @@ -83,7 +83,12 @@ def example_plot(ax): example_plot(ax2) example_plot(ax3) -gs1.tight_layout(fig, rect=[None, None, 0.45, None]) +with warnings.catch_warnings(): + warnings.simplefilter("ignore", UserWarning) + # This raises warnings since tight layout cannot + # handle gridspec automatically. We are going to + # do that manually so we can filter the warning. + gs1.tight_layout(fig, rect=[None, None, 0.45, None]) gs2 = gridspec.GridSpec(2, 1) ax4 = fig.add_subplot(gs2[0]) @@ -92,7 +97,12 @@ def example_plot(ax): #example_plot(ax4) #example_plot(ax5) -gs2.tight_layout(fig, rect=[0.45, None, None, None]) +with warnings.catch_warnings(): + # This raises warnings since tight layout cannot + # handle gridspec automatically. We are going to + # do that manually so we can filter the warning. + warnings.simplefilter("ignore", UserWarning) + gs2.tight_layout(fig, rect=[0.45, None, None, None]) # now match the top and bottom of two gridspecs. top = min(gs1.top, gs2.top) From 4ebeee5d00dcae131ad0c06a5a506fd925ef6e31 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Sun, 28 Dec 2014 14:20:45 +0100 Subject: [PATCH 4/6] Reenable plots in tight layout demo --- examples/pylab_examples/demo_tight_layout.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/pylab_examples/demo_tight_layout.py b/examples/pylab_examples/demo_tight_layout.py index bcdeef3cc05a..88a5c37dc7b9 100644 --- a/examples/pylab_examples/demo_tight_layout.py +++ b/examples/pylab_examples/demo_tight_layout.py @@ -94,8 +94,8 @@ def example_plot(ax): ax4 = fig.add_subplot(gs2[0]) ax5 = fig.add_subplot(gs2[1]) -#example_plot(ax4) -#example_plot(ax5) +example_plot(ax4) +example_plot(ax5) with warnings.catch_warnings(): # This raises warnings since tight layout cannot From 80bf9f6b6e78a200984d84f69057384bfce33ec7 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 29 Dec 2014 11:42:47 +0100 Subject: [PATCH 5/6] Hexbin, Dont calculate mean of empty slice Avoids numpy warnings with the same result. Similar to what is done above --- lib/matplotlib/axes/_axes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 64f3b53f4a0b..81352c360596 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4065,7 +4065,11 @@ def coarse_bin(x, y, coarse): ind = coarse.searchsorted(x).clip(0, len(coarse) - 1) mus = np.zeros(len(coarse)) for i in range(len(coarse)): - mu = reduce_C_function(y[ind == i]) + yi = y[ind == i] + if len(yi) > 0: + mu = reduce_C_function(yi) + else: + mu = np.nan mus[i] = mu return mus From e8f1ed736a126123fe0881b60d509b5a3465f153 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Thu, 1 Jan 2015 19:52:10 +0100 Subject: [PATCH 6/6] Clarify why we filter warnings in angle_helper.py --- lib/mpl_toolkits/axisartist/angle_helper.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/axisartist/angle_helper.py b/lib/mpl_toolkits/axisartist/angle_helper.py index feab84a6940a..5d921b0ba553 100644 --- a/lib/mpl_toolkits/axisartist/angle_helper.py +++ b/lib/mpl_toolkits/axisartist/angle_helper.py @@ -385,7 +385,11 @@ def __call__(self, transform_xy, x1, y1, x2, y2): lon, lat = transform_xy(np.ravel(x), np.ravel(y)) # iron out jumps, but algorithm should be improved. - # Tis is just naive way of doing and my fail for some cases. + # This is just naive way of doing and my fail for some cases. + # Consider replacing this with numpy.unwrap + # We are ignoring invalid warnings. They are triggered when + # comparing arrays with NaNs using > We are already handling + # that correctly using np.nanmin and np.nanmax with np.errstate(invalid='ignore'): if self.lon_cycle is not None: lon0 = np.nanmin(lon)