10000 Catch warning thrown in Mollweide projection. by jenshnielsen · Pull Request #3282 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Catch warning thrown in Mollweide projection. #3282

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

Merged
merged 2 commits into from
Aug 26, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Catch warning thrown in Mollweide projection.
This happens when plotting tries to expand
the interval for ticks beyond the defined region and do np.arcsin(y/sqrt(2))
where y is larger that sqrt(2) since the original limites matches the allowed
interval.

And Improve warnings message to clarify that this is related to ticks only.

Also some PEP8 around the code that I changed.
  • Loading branch information
jenshnielsen committed Jul 22, 2014
commit ef2c5fab05565bbe82693745025fcfd1a3a2db8f
40 changes: 26 additions & 14 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,20 +1010,32 @@ def _update_ticks(self, renderer):
# the idea that one would rather potentially lose a tick
# from one side of the axis or another, rather than see a
# stack trace.
try:
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0], -0.5)
except:
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
ds1 = 0.0
if np.isnan(ds1):
ds1 = 0.0
try:
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1], +0.5)
except:
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
ds2 = 0.0
if np.isnan(ds2):
ds2 = 0.0
# We also catch users warnings here. These are the result of
# invalid numpy calculations that may be the result of out of
# bounds on axis with finite allowed intervals such as geo
# projections i.e. Mollweide.
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=RuntimeWarning)
try:
ds1 = self._get_pixel_distance_along_axis(
interval_expanded[0], -0.5)
except:
warnings.warn("Unable to find pixel distance along axis for\
interval padding of ticks; assuming no interval padding\
needed.")
ds1 = 0.0
if np.isnan(ds1):
ds1 = 0.0
try:
ds2 = self._get_pixel_distance_along_axis(
interval_expanded[1], +0.5)
except:
warnings.warn("Unable to find pixel distance along axis for\
interval padding of ticks; assuming no interval padding\
needed.")
ds2 = 0.0
if np.isnan(ds2):
ds2 = 0.0
interval_expanded = (interval_expanded[0] - ds1,
interval_expanded[1] + ds2)

Expand Down
0