Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c9eba3

Browse files
committed
Merge pull request matplotlib#3282 from jenshnielsen/mollweide_warning
Catch warning thrown in Mollweide projection.
1 parent 4284599 commit 3c9eba3

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

lib/matplotlib/axis.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,20 +1010,31 @@ def _update_ticks(self, renderer):
10101010
# the idea that one would rather potentially lose a tick
10111011
# from one side of the axis or another, rather than see a
10121012
# stack trace.
1013-
try:
1014-
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0], -0.5)
1015-
except:
1016-
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
1017-
ds1 = 0.0
1018-
if np.isnan(ds1):
1019-
ds1 = 0.0
1020-
try:
1021-
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1], +0.5)
1022-
except:
1023-
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
1024-
ds2 = 0.0
1025-
if np.isnan(ds2):
1026-
ds2 = 0.0
1013+
# We also catch users warnings here. These are the result of
1014+
# invalid numpy calculations that may be the result of out of
1015+
# bounds on axis with finite allowed intervals such as geo
1016+
# projections i.e. Mollweide.
1017+
with np.errstate(invalid='ignore'):
1018+
try:
1019+
ds1 = self._get_pixel_distance_along_axis(
1020+
interval_expanded[0], -0.5)
1021+
except:
1022+
warnings.warn("Unable to find pixel distance along axis for\
1023+
interval padding of ticks; assuming no interval padding\
1024+
needed.")
1025+
ds1 = 0.0
1026+
if np.isnan(ds1):
1027+
ds1 = 0.0
1028+
try:
1029+
ds2 = self._get_pixel_distance_along_axis(
1030+
interval_expanded[1], +0.5)
1031+
except:
1032+
warnings.warn("Unable to find pixel distance along axis for\
1033+
interval padding of ticks; assuming no interval padding\
1034+
needed.")
1035+
ds2 = 0.0
1036+
if np.isnan(ds2):
1037+
ds2 = 0.0
10271038
interval_expanded = (interval_expanded[0] - ds1,
10281039
interval_expanded[1] + ds2)
10291040

0 commit comments

Comments
 (0)