Skip to content

Commit

Permalink
Merge pull request #3958 from jenshnielsen/examples_filter_warnings
Browse files Browse the repository at this point in the history
Supress some warnings in examples
  • Loading branch information
WeatherGod committed Jan 1, 2015
2 parents d8b2924 + e8f1ed7 commit 9b661e7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
22 changes: 16 additions & 6 deletions 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]
Expand Down Expand Up @@ -83,16 +83,26 @@ 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])
ax5 = fig.add_subplot(gs2[1])

#example_plot(ax4)
#example_plot(ax5)

gs2.tight_layout(fig, rect=[0.45, None, None, None])
example_plot(ax4)
example_plot(ax5)

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)
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/axes/_axes.py
Expand Up @@ -4054,7 +4054,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

Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/projections/polar.py
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions lib/mpl_toolkits/axisartist/angle_helper.py
Expand Up @@ -385,13 +385,18 @@ 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.
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.)
# 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)
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)
Expand Down

0 comments on commit 9b661e7

Please sign in to comment.