1313import mpl_toolkits .axisartist .angle_helper as angle_helper
1414import numpy as np
1515from matplotlib .projections import PolarAxes
16- from matplotlib .transforms import Affine2D , Bbox
16+ from matplotlib .transforms import Affine2D
1717from mpl_toolkits .axisartist import SubplotHost
1818from mpl_toolkits .axisartist .grid_helper_curvelinear import \
1919 GridHelperCurveLinear
@@ -31,67 +31,6 @@ def __call__(self, direction, factor, values):
3131 return ret
3232
3333
34- class ModifiedExtremeFinderCycle (angle_helper .ExtremeFinderCycle ):
35- """Changed to allow only left hand-side polar grid.
36-
37- https://matplotlib.org/_modules/mpl_toolkits/axisartist/angle_helper.html#ExtremeFinderCycle.__call__
38- """
39- 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-
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
50- return lon_min , lon_max , lat_min , lat_max
51-
52- def _find_transformed_bbox (self , trans , bbox ):
53- """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."""
58- grid = np .reshape (np .meshgrid (
59- np .linspace (bbox .x0 , bbox .x1 , self .nx ),
60- np .linspace (bbox .y0 , bbox .y1 , self .ny )), (2 , - 1 )).T
61- lon , lat = transform (grid ).T
62-
63- with np .errstate (invalid = 'ignore' ):
64- if self .lon_cycle is not None :
65- lon0 = np .nanmin (lon )
66- # Changed from 180 to 360 to be able to span only
67- # 90-270 (left hand side)
68- lon -= 360. * ((lon - lon0 ) > 360. )
69- if self .lat_cycle is not None : # pragma: no cover
70- lat0 = np .nanmin (lat )
71- lat -= 360. * ((lat - lat0 ) > 180. )
72-
73- transformed_bbox = Bbox .null ()
74- transformed_bbox .update_from_data_xy (np .column_stack ([lon , lat ]))
75- transformed_bbox = transformed_bbox .expanded (
76- 1 + 2 / self .nx , 1 + 2 / self .ny )
77- lon_min , lat_min , lon_max , lat_max = transformed_bbox .extents
78-
79- if self .lon_cycle :
80- lon_max = min (lon_max , lon_min + self .lon_cycle )
81- if self .lat_cycle : # pragma: no cover
82- lat_max = min (lat_max , lat_min + self .lat_cycle )
83-
84- if self .lon_minmax is not None :
85- lon_min = max (self .lon_minmax [0 ], lon_min )
86- lon_max = min (self .lon_minmax [1 ], lon_max )
87-
88- if self .lat_minmax is not None :
89- lat_min = max (self .lat_minmax [0 ], lat_min )
90- lat_max = min (self .lat_minmax [1 ], lat_max )
91-
92- return Bbox .from_extents (lon_min , lat_min , lon_max , lat_max )
93-
94-
9534def sgrid (subplot = (1 , 1 , 1 ), scaling = None ):
9635 # From matplotlib demos:
9736 # https://matplotlib.org/gallery/axisartist/demo_curvelinear_grid.html
@@ -101,14 +40,14 @@ def sgrid(subplot=(1, 1, 1), scaling=None):
10140 # system in degrees
10241 tr = Affine2D ().scale (np .pi / 180. , 1. ) + PolarAxes .PolarTransform ()
10342
104- # polar projection, which involves cycle, and also has limits in
105- # its coordinates, needs a special method to find the extremes
106- # (min, max of the coordinate within the view) .
43+ # The s-plane grid spans the fixed longitude interval 90-270 degrees.
44+ # Disable cycle unwrapping at the 180-degree boundary and use lon_minmax
45+ # to clip the grid to the left half-plane .
10746
10847 # 20, 20 : number of sampling points along x, y direction
10948 sampling_points = 20
110- extreme_finder = ModifiedExtremeFinderCycle (
111- sampling_points , sampling_points , lon_cycle = 360 , lat_cycle = None ,
49+ extreme_finder = angle_helper . ExtremeFinderCycle (
50+ sampling_points , sampling_points , lon_cycle = None , lat_cycle = None ,
11251 lon_minmax = (90 , 270 ), lat_minmax = (0 , np .inf ),)
11352
11453 grid_locator1 = angle_helper .LocatorDMS (15 )
0 commit comments