1313import mpl_toolkits .axisartist .angle_helper as angle_helper
1414import numpy as np
1515from matplotlib .projections import PolarAxes
16- from matplotlib .transforms import Affine2D
16+ from matplotlib .transforms import Affine2D , Bbox
1717from mpl_toolkits .axisartist import SubplotHost
1818from mpl_toolkits .axisartist .grid_helper_curvelinear import \
1919 GridHelperCurveLinear
@@ -37,6 +37,12 @@ class ModifiedExtremeFinderCycle(angle_helper.ExtremeFinderCycle):
3737 https://matplotlib.org/_modules/mpl_toolkits/axisartist/angle_helper.html#ExtremeFinderCycle.__call__
3838 """
3939 def __call__ (self , transform_xy , x1 , y1 , x2 , y2 ):
40+ # Matplotlib 3.11 moved this calculation to
41+ # _find_transformed_bbox(), which is also called directly by
42+ # GridFinder. Keep the legacy implementation for older releases.
43+ if hasattr (super (), '_find_transformed_bbox' ):
44+ return super ().__call__ (transform_xy , x1 , y1 , x2 , y2 )
45+
4046 x , y = np .meshgrid (
4147 np .linspace (x1 , x2 , self .nx ), np .linspace (y1 , y2 , self .ny ))
4248 lon , lat = transform_xy (np .ravel (x ), np .ravel (y ))
@@ -77,6 +83,44 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
7783
7884 return lon_min , lon_max , lat_min , lat_max
7985
86+ def _find_transformed_bbox (self , trans , bbox ):
87+ """Find grid extremes using the Matplotlib 3.11 interface."""
88+ grid = np .reshape (np .meshgrid (
89+ np .linspace (bbox .x0 , bbox .x1 , self .nx ),
90+ np .linspace (bbox .y0 , bbox .y1 , self .ny )), (2 , - 1 )).T
91+ lon , lat = trans .transform (grid ).T
92+
93+ with np .errstate (invalid = 'ignore' ):
94+ if self .lon_cycle is not None :
95+ lon0 = np .nanmin (lon )
96+ # Changed from 180 to 360 to be able to span only
97+ # 90-270 (left hand side)
98+ lon -= 360. * ((lon - lon0 ) > 360. )
99+ if self .lat_cycle is not None : # pragma: no cover
100+ lat0 = np .nanmin (lat )
101+ lat -= 360. * ((lat - lat0 ) > 180. )
102+
103+ transformed_bbox = Bbox .null ()
104+ transformed_bbox .update_from_data_xy (np .column_stack ([lon , lat ]))
105+ transformed_bbox = transformed_bbox .expanded (
106+ 1 + 2 / self .nx , 1 + 2 / self .ny )
107+ lon_min , lat_min , lon_max , lat_max = transformed_bbox .extents
108+
109+ if self .lon_cycle :
110+ lon_max = min (lon_max , lon_min + self .lon_cycle )
111+ if self .lat_cycle : # pragma: no cover
112+ lat_max = min (lat_max , lat_min + self .lat_cycle )
113+
114+ if self .lon_minmax is not None :
115+ lon_min = max (self .lon_minmax [0 ], lon_min )
116+ lon_max = min (self .lon_minmax [1 ], lon_max )
117+
118+ if self .lat_minmax is not None :
119+ lat_min = max (self .lat_minmax [0 ], lat_min )
120+ lat_max = min (self .lat_minmax [1 ], lat_max )
121+
122+ return Bbox .from_extents (lon_min , lat_min , lon_max , lat_max )
123+
80124
81125def sgrid (subplot = (1 , 1 , 1 ), scaling = None ):
82126 # From matplotlib demos:
0 commit comments