Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a105bba

Browse files
committed
Use path extents to get path autoscale limits
1 parent ad95791 commit a105bba

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,23 +2374,28 @@ def _update_patch_limits(self, patch):
23742374
((not patch.get_width()) and (not patch.get_height()))):
23752375
return
23762376
p = patch.get_path()
2377-
vertices = p.vertices if p.codes is None else p.vertices[np.isin(
2378-
p.codes, (mpath.Path.CLOSEPOLY, mpath.Path.STOP), invert=True)]
2379-
if not vertices.size:
2380-
return
2381-
patch_trf = patch.get_transform()
2382-
updatex, updatey = patch_trf.contains_branch_seperately(self.transData)
2383-
if not (updatex or updatey):
2384-
return
2385-
if self.name != "rectilinear":
2386-
# As in _update_line_limits, but for axvspan.
2387-
if updatex and patch_trf == self.get_yaxis_transform():
2388-
updatex = False
2389-
if updatey and patch_trf == self.get_xaxis_transform():
2390-
updatey = False
2391-
trf_to_data = patch_trf - self.transData
2392-
xys = trf_to_data.transform(vertices)
2393-
self.update_datalim(xys, updatex=updatex, updatey=updatey)
2377+
# Get all vertices on the path
2378+
# Loop through each sement to get extrema (as opposed to control points)
2379+
# for Bezier curve sections
2380+
vertices = []
2381+
for curve, code in p.iter_bezier():
2382+
_, dzeros = curve.axis_aligned_extrema()
2383+
# as can the ends of the curve
2384+
vertices.append(curve([0, *dzeros, 1]))
2385+
2386+
if len(vertices):
2387+
vertices = np.row_stack(vertices)
2388+
2389+
xys = patch.get_patch_transform().transform(vertices)
2390+
if patch.get_data_transform() != self.transData:
2391+
patch_to_data = (patch.get_data_transform() -
2392+
self.transData)
2393+
xys = patch_to_data.transform(xys)
2394+
2395+
updatex, updatey = patch.get_transform().\
2396+
contains_branch_seperately(self.transData)
2397+
self.update_datalim(xys, updatex=updatex,
2398+
updatey=updatey)
23942399

23952400
def add_table(self, tab):
23962401
"""

0 commit comments

Comments
 (0)