@@ -43,52 +43,22 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
4343 if hasattr (super (), '_find_transformed_bbox' ):
4444 return super ().__call__ (transform_xy , x1 , y1 , x2 , y2 )
4545
46- x , y = np .meshgrid (
47- np .linspace (x1 , x2 , self .nx ), np .linspace (y1 , y2 , self .ny ))
48- lon , lat = transform_xy (np .ravel (x ), np .ravel (y ))
49-
50- with np .errstate (invalid = 'ignore' ):
51- if self .lon_cycle is not None :
52- lon0 = np .nanmin (lon )
53- # Changed from 180 to 360 to be able to span only
54- # 90-270 (left hand side)
55- lon -= 360. * ((lon - lon0 ) > 360. )
56- if self .lat_cycle is not None : # pragma: no cover
57- lat0 = np .nanmin (lat )
58- lat -= 360. * ((lat - lat0 ) > 180. )
59-
60- lon_min , lon_max = np .nanmin (lon ), np .nanmax (lon )
61- lat_min , lat_max = np .nanmin (lat ), np .nanmax (lat )
62-
63- lon_min , lon_max , lat_min , lat_max = \
64- self ._add_pad (lon_min , lon_max , lat_min , lat_max )
65-
66- # check cycle
67- if self .lon_cycle :
68- lon_max = min (lon_max , lon_min + self .lon_cycle )
69- if self .lat_cycle : # pragma: no cover
70- lat_max = min (lat_max , lat_min + self .lat_cycle )
71-
72- if self .lon_minmax is not None :
73- min0 = self .lon_minmax [0 ]
74- lon_min = max (min0 , lon_min )
75- max0 = self .lon_minmax [1 ]
76- lon_max = min (max0 , lon_max )
77-
78- if self .lat_minmax is not None :
79- min0 = self .lat_minmax [0 ]
80- lat_min = max (min0 , lat_min )
81- max0 = self .lat_minmax [1 ]
82- lat_max = min (max0 , lat_max )
83-
46+ transformed_bbox = self ._find_extremes (
47+ lambda points : np .column_stack (transform_xy (* points .T )),
48+ Bbox .from_extents (x1 , y1 , x2 , y2 ))
49+ lon_min , lat_min , lon_max , lat_max = transformed_bbox .extents
8450 return lon_min , lon_max , lat_min , lat_max
8551
8652 def _find_transformed_bbox (self , trans , bbox ):
8753 """Find grid extremes using the Matplotlib 3.11 interface."""
54+ return self ._find_extremes (trans .transform , bbox )
55+
56+ def _find_extremes (self , transform , bbox ):
57+ """Find grid extremes using a point-array transform."""
8858 grid = np .reshape (np .meshgrid (
8959 np .linspace (bbox .x0 , bbox .x1 , self .nx ),
9060 np .linspace (bbox .y0 , bbox .y1 , self .ny )), (2 , - 1 )).T
91- lon , lat = trans . transform (grid ).T
61+ lon , lat = transform (grid ).T
9262
9363 with np .errstate (invalid = 'ignore' ):
9464 if self .lon_cycle is not None :
0 commit comments