From 527faa49df915d33560f98d9eb326e693d43db81 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 7 Dec 2020 16:19:37 +0100 Subject: [PATCH] Small improvements to aitoff projection. - Use np.sinc instead of rewriting it ourselves. (This way, if numpy ever switches sinc to C, we get the speedup too.) - Make InvertedAitoff return nan (which is clearly suggests "we can't compute this") instead of being a noop (which makes it return nonsensical data with no user warning). AFAICT this is only used to print mouseover coordinates. See e.g. `subplots_axes_and_figures/geo_demo.py` where the mouseover coordinates for aitoff were just completely wrong. --- lib/matplotlib/projections/geo.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index c169e4587d5b..4aa374c5d75d 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -264,10 +264,7 @@ def transform_non_affine(self, ll): cos_latitude = np.cos(latitude) alpha = np.arccos(cos_latitude * np.cos(half_long)) - # Avoid divide-by-zero errors using same method as NumPy. - alpha[alpha == 0.0] = 1e-20 - # We want unnormalized sinc. numpy.sinc gives us normalized - sinc_alpha = np.sin(alpha) / alpha + sinc_alpha = np.sinc(alpha / np.pi) # np.sinc is sin(pi*x)/(pi*x). x = (cos_latitude * np.sin(half_long)) / sinc_alpha y = np.sin(latitude) / sinc_alpha @@ -282,7 +279,7 @@ class InvertedAitoffTransform(_GeoTransform): def transform_non_affine(self, xy): # docstring inherited # MGDTODO: Math is hard ;( - return xy + return np.full_like(xy, np.nan) def inverted(self): # docstring inherited