7
7
8
8
import numpy as np
9
9
10
- from matplotlib import cbook
10
+ from matplotlib import _api , cbook
11
11
import matplotlib .patches as mpatches
12
12
from matplotlib .path import Path
13
13
import matplotlib .axes as maxes
@@ -287,6 +287,7 @@ def get_gridlines(self, which="major", axis="both"):
287
287
grid_lines .extend (self ._grid_info ["lat_lines" ])
288
288
return grid_lines
289
289
290
+ @_api .deprecated ("3.5" )
290
291
def get_boundary (self ):
291
292
"""
292
293
Return (N, 2) array of (x, y) coordinate of the boundary.
@@ -322,11 +323,19 @@ def __init__(self, *args, **kwargs):
322
323
323
324
def _gen_axes_patch (self ):
324
325
# docstring inherited
325
- return mpatches .Polygon (self .get_grid_helper ().get_boundary ())
326
+ # Using a public API to access _extremes.
327
+ (x0 , _ ), (x1 , _ ), (y0 , _ ), (y1 , _ ) = map (
328
+ self .get_grid_helper ().get_data_boundary ,
329
+ ["left" , "right" , "bottom" , "top" ])
330
+ patch = mpatches .Polygon ([(x0 , y0 ), (x1 , y0 ), (x1 , y1 ), (x0 , y1 )])
331
+ patch .get_path ()._interpolation_steps = 100
332
+ return patch
326
333
327
334
def cla (self ):
328
335
super ().cla ()
329
- self .patch .set_transform (self .transData )
336
+ self .patch .set_transform (
337
+ self .get_grid_helper ().grid_finder .get_transform ()
338
+ + self .transData )
330
339
# The original patch is not in the draw tree; it is only used for
331
340
# clipping purposes.
332
341
orig_patch = super ()._gen_axes_patch ()
@@ -336,18 +345,12 @@ def cla(self):
336
345
self .gridlines .set_clip_path (orig_patch )
337
346
338
347
def adjust_axes_lim (self ):
339
- grid_helper = self .get_grid_helper ()
340
- t = grid_helper .get_boundary ()
341
- x , y = t [:, 0 ], t [:, 1 ]
342
-
343
- xmin , xmax = min (x ), max (x )
344
- ymin , ymax = min (y ), max (y )
345
-
346
- dx = (xmax - xmin ) / 100
347
- dy = (ymax - ymin ) / 100
348
-
349
- self .set_xlim (xmin - dx , xmax + dx )
350
- self .set_ylim (ymin - dy , ymax + dy )
348
+ bbox = self .patch .get_path ().get_extents (
349
+ # First transform to pixel coords, then to parent data coords.
350
+ self .patch .get_transform () - self .transData )
351
+ bbox = bbox .expanded (1.02 , 1.02 )
352
+ self .set_xlim (bbox .xmin , bbox .xmax )
353
+ self .set_ylim (bbox .ymin , bbox .ymax )
351
354
352
355
353
356
floatingaxes_class_factory = cbook ._make_class_factory (
0 commit comments