From ef2c5fab05565bbe82693745025fcfd1a3a2db8f Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 21 Jul 2014 15:20:23 +0100 Subject: [PATCH 1/2] 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. --- lib/matplotlib/axis.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 80ceed5de7e3..796a599cf417 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -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) From ffe211e342408ebef0d93c131b71fc7b3b9f881f Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Mon, 21 Jul 2014 11:39:07 -0700 Subject: [PATCH 2/2] Filter warnings with more selective np.errstate context --- lib/matplotlib/axis.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 796a599cf417..6f2b24c1793f 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1014,8 +1014,7 @@ def _update_ticks(self, renderer): # 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) + with np.errstate(invalid='ignore'): try: ds1 = self._get_pixel_distance_along_axis( interval_expanded[0], -0.5)