Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b661e7

Browse filesBrowse files
committed
Merge pull request matplotlib#3958 from jenshnielsen/examples_filter_warnings
Supress some warnings in examples
2 parents d8b2924 + e8f1ed7 commit 9b661e7
Copy full SHA for 9b661e7

4 files changed

+40-15Lines changed: 40 additions & 15 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎examples/pylab_examples/demo_tight_layout.py‎

Copy file name to clipboardExpand all lines: examples/pylab_examples/demo_tight_layout.py
+16-6Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import matplotlib.pyplot as plt
3-
3+
import warnings
44

55
import random
66
fontsizes = [8, 16, 24, 32]
@@ -83,16 +83,26 @@ def example_plot(ax):
8383
example_plot(ax2)
8484
example_plot(ax3)
8585

86-
gs1.tight_layout(fig, rect=[None, None, 0.45, None])
86+
with warnings.catch_warnings():
87+
warnings.simplefilter("ignore", UserWarning)
88+
# This raises warnings since tight layout cannot
89+
# handle gridspec automatically. We are going to
90+
# do that manually so we can filter the warning.
91+
gs1.tight_layout(fig, rect=[None, None, 0.45, None])
8792

8893
gs2 = gridspec.GridSpec(2, 1)
8994
ax4 = fig.add_subplot(gs2[0])
9095
ax5 = fig.add_subplot(gs2[1])
9196

92-
#example_plot(ax4)
93-
#example_plot(ax5)
94-
95-
gs2.tight_layout(fig, rect=[0.45, None, None, None])
97+
example_plot(ax4)
98+
example_plot(ax5)
99+
100+
with warnings.catch_warnings():
101+
# This raises warnings since tight layout cannot
102+
# handle gridspec automatically. We are going to
103+
# do that manually so we can filter the warning.
104+
warnings.simplefilter("ignore", UserWarning)
105+
gs2.tight_layout(fig, rect=[0.45, None, None, None])
96106

97107
# now match the top and bottom of two gridspecs.
98108
top = min(gs1.top, gs2.top)
Collapse file

‎lib/matplotlib/axes/_axes.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4054,7 +4054,11 @@ def coarse_bin(x, y, coarse):
40544054
ind = coarse.searchsorted(x).clip(0, len(coarse) - 1)
40554055
mus = np.zeros(len(coarse))
40564056
for i in range(len(coarse)):
4057-
mu = reduce_C_function(y[ind == i])
4057+
yi = y[ind == i]
4058+
if len(yi) > 0:
4059+
mu = reduce_C_function(yi)
4060+
else:
4061+
mu = np.nan
40584062
mus[i] = mu
40594063
return mus
40604064

Collapse file

‎lib/matplotlib/projections/polar.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ def transform_non_affine(self, xy):
146146
x = xy[:, 0:1]
147147
y = xy[:, 1:]
148148
r = np.sqrt(x*x + y*y)
149-
theta = np.arccos(x / r)
149+
with np.errstate(invalid='ignore'):
150+
# At x=y=r=0 this will raise an
151+
# invalid value warning when doing 0/0
152+
# Divide by zero warnings are only raised when
153+
# the numerator is different from 0. That
154+
# should not happen here.
155+
theta = np.arccos(x / r)
150156
theta = np.where(y < 0, 2 * np.pi - theta, theta)
151157

152158
theta -= theta_offset
Collapse file

‎lib/mpl_toolkits/axisartist/angle_helper.py‎

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axisartist/angle_helper.py
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,18 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
385385
lon, lat = transform_xy(np.ravel(x), np.ravel(y))
386386

387387
# iron out jumps, but algorithm should be improved.
388-
# Tis is just naive way of doing and my fail for some cases.
389-
if self.lon_cycle is not None:
390-
lon0 = np.nanmin(lon)
391-
lon -= 360. * ((lon - lon0) > 180.)
392-
if self.lat_cycle is not None:
393-
lat0 = np.nanmin(lat)
394-
lat -= 360. * ((lat - lat0) > 180.)
388+
# This is just naive way of doing and my fail for some cases.
389+
# Consider replacing this with numpy.unwrap
390+
# We are ignoring invalid warnings. They are triggered when
391+
# comparing arrays with NaNs using > We are already handling
392+
# that correctly using np.nanmin and np.nanmax
393+
with np.errstate(invalid='ignore'):
394+
if self.lon_cycle is not None:
395+
lon0 = np.nanmin(lon)
396+
lon -= 360. * ((lon - lon0) > 180.)
397+
if self.lat_cycle is not None:
398+
lat0 = np.nanmin(lat)
399+
lat -= 360. * ((lat - lat0) > 180.)
395400

396401
lon_min, lon_max = np.nanmin(lon), np.nanmax(lon)
397402
lat_min, lat_max = np.nanmin(lat), np.nanmax(lat)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.