77
88import numpy as np
99
10- from matplotlib import cbook
10+ from matplotlib import _api , cbook
1111import matplotlib .patches as mpatches
1212from matplotlib .path import Path
1313import matplotlib .axes as maxes
@@ -287,6 +287,7 @@ def get_gridlines(self, which="major", axis="both"):
287287 grid_lines .extend (self ._grid_info ["lat_lines" ])
288288 return grid_lines
289289
290+ @_api .deprecated ("3.5" )
290291 def get_boundary (self ):
291292 """
292293 Return (N, 2) array of (x, y) coordinate of the boundary.
@@ -322,11 +323,19 @@ def __init__(self, *args, **kwargs):
322323
323324 def _gen_axes_patch (self ):
324325 # 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
326333
327334 def cla (self ):
328335 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 )
330339 # The original patch is not in the draw tree; it is only used for
331340 # clipping purposes.
332341 orig_patch = super ()._gen_axes_patch ()
@@ -336,18 +345,12 @@ def cla(self):
336345 self .gridlines .set_clip_path (orig_patch )
337346
338347 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 )
351354
352355
353356floatingaxes_class_factory = cbook ._make_class_factory (
0 commit comments