@@ -160,9 +160,10 @@ def plot_intensity(
160160
161161 raise ValueError ("Provide one event id or one centroid id." )
162162
163+ @staticmethod
163164 def plot_track_density (
164165 hist : np .ndarray ,
165- ax = None ,
166+ axis = None ,
166167 projection = ccrs .Mollweide (),
167168 add_features : dict = None ,
168169 title : str = None ,
@@ -182,13 +183,13 @@ def plot_track_density(
182183 ----------
183184 hist: np.ndarray
184185 2D histogram of track density.
185- ax : GeoAxes, optional
186+ axis : GeoAxes, optional
186187 Existing Cartopy axis.
187188 projection: cartopy.crs, optional
188189 Projection for the map.
189190 add_features: dict
190- Dictionary of map features to add. Keys can be 'land', 'coastline', 'borders', and 'lakes'.
191- Values are Booleans indicating whether to include each feature.
191+ Dictionary of map features to add. Keys can be 'land', 'coastline', 'borders', and
192+ 'lakes'. Values are Booleans indicating whether to include each feature.
192193 title: str
193194 Title of the plot.
194195 figsize: tuple
@@ -200,16 +201,18 @@ def plot_track_density(
200201
201202 Returns:
202203 -------
203- ax : GeoAxes
204+ axis : GeoAxes
204205 The plot axis.
205206
206207
207208 Example:
208209 --------
209- >>> ax = plot_track_density(
210+ >>> axis = plot_track_density(
210211 ... hist=hist,
211212 ... cmap='Spectral_r',
212- ... cbar_kwargs={'shrink': 0.8, 'label': 'Cyclone Density [n° tracks / km²]', 'pad': 0.1},
213+ ... cbar_kwargs={'shrink': 0.8,
214+ 'label': 'Cyclone Density [n° tracks / km²]',
215+ 'pad': 0.1},
213216 ... add_features={
214217 ... 'land': True,
215218 ... 'coastline': True,
@@ -233,13 +236,12 @@ def plot_track_density(
233236 add_features = add_features or default_features
234237
235238 # Sample data
236- x = np .linspace (- 180 , 180 , hist .shape [1 ])
237- y = np .linspace (- 90 , 90 , hist .shape [0 ])
238- z = hist
239+ lon = np .linspace (- 180 , 180 , hist .shape [1 ])
240+ lat = np .linspace (- 90 , 90 , hist .shape [0 ])
239241
240242 # Create figure and axis if not provided
241- if ax is None :
242- fig , ax = plt .subplots (
243+ if axis is None :
244+ _ , axis = plt .subplots (
243245 figsize = figsize , subplot_kw = {"projection" : projection }
244246 )
245247
@@ -252,24 +254,24 @@ def plot_track_density(
252254 facecolor = "lightgrey" ,
253255 alpha = 0.6 ,
254256 )
255- ax .add_feature (land )
257+ axis .add_feature (land )
256258 if add_features .get ("coastline" , False ):
257- ax .add_feature (cfeature .COASTLINE , linewidth = 0.5 )
259+ axis .add_feature (cfeature .COASTLINE , linewidth = 0.5 )
258260 if add_features .get ("borders" , False ):
259- ax .add_feature (cfeature .BORDERS , linestyle = ":" )
261+ axis .add_feature (cfeature .BORDERS , linestyle = ":" )
260262 if add_features .get ("lakes" , False ):
261- ax .add_feature (cfeature .LAKES , alpha = 0.4 , edgecolor = "black" )
263+ axis .add_feature (cfeature .LAKES , alpha = 0.4 , edgecolor = "black" )
262264
263265 # Plot density with contourf
264- contourf = ax .contourf (x , y , z , transform = ccrs .PlateCarree (), ** kwargs )
266+ contourf = axis .contourf (lon , lat , hist , transform = ccrs .PlateCarree (), ** kwargs )
265267
266268 # Add colorbar
267- cbar = plt .colorbar (contourf , ax = ax , ** cbar_kwargs )
269+ plt .colorbar (contourf , ax = axis , ** cbar_kwargs )
268270 # Title setup
269271 if title :
270- ax .set_title (title , fontsize = 16 )
272+ axis .set_title (title , fontsize = 16 )
271273
272- return ax
274+ return axis
273275
274276 def plot_fraction (self , event = None , centr = None , smooth = True , axis = None , ** kwargs ):
275277 """Plot fraction values for a selected event or centroid.
0 commit comments