Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress some warnings in examples #3958

Merged
merged 6 commits into from Jan 1, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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

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
13 changes: 7 additions & 6 deletions lib/mpl_toolkits/axisartist/angle_helper.py
Expand Up @@ -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'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self, should probably use np.unroll() here, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, what exactly are we ignoring here? The other changes came with very nice explanations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right you are. I guess I was being lazy 😃
I assume that np.unroll() should we np.unwrap?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, right, np.unwrap(). Squishy brain matter makes for a terrible memory medium...

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