Skip to content

Commit bbc50e4

Browse files
authored
Merge pull request matplotlib#19214 from dstansby/bezier-autoscale
Improve autoscaling for high order Bezier curves
2 parents dc11ded + 7036d2d commit bbc50e4

File tree

11 files changed

+45
-11
lines changed

11 files changed

+45
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Improved autoscaling for bezier curves
2+
--------------------------------------
3+
Bezier curves are now autoscaled to their extents - previously they were
4+
autoscaled to their ends and control points, which in some cases led to
5+
unnecessarily large limits.

lib/matplotlib/axes/_base.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import matplotlib.image as mimage
2323
import matplotlib.lines as mlines
2424
import matplotlib.patches as mpatches
25-
import matplotlib.path as mpath
2625
from matplotlib.rcsetup import cycler, validate_axisbelow
2726
import matplotlib.spines as mspines
2827
import matplotlib.table as mtable
@@ -2382,10 +2381,18 @@ def _update_patch_limits(self, patch):
23822381
((not patch.get_width()) and (not patch.get_height()))):
23832382
return
23842383
p = patch.get_path()
2385-
vertices = p.vertices if p.codes is None else p.vertices[np.isin(
2386-
p.codes, (mpath.Path.CLOSEPOLY, mpath.Path.STOP), invert=True)]
2387-
if not vertices.size:
2388-
return
2384+
# Get all vertices on the path
2385+
# Loop through each sement to get extrema for Bezier curve sections
2386+
vertices = []
2387+
for curve, code in p.iter_bezier():
2388+
# Get distance along the curve of any extrema
2389+
_, dzeros = curve.axis_aligned_extrema()
2390+
# Calculate vertcies of start, end and any extrema in between
2391+
vertices.append(curve([0, *dzeros, 1]))
2392+
2393+
if len(vertices):
2394+
vertices = np.row_stack(vertices)
2395+
23892396
patch_trf = patch.get_transform()
23902397
updatex, updatey = patch_trf.contains_branch_seperately(self.transData)
23912398
if not (updatex or updatey):
-27.4 KB
Loading
-12.1 KB
Loading
268 Bytes
Loading
-16.8 KB
Loading
-11.1 KB
Loading
-30.7 KB
Loading
111 Bytes
Loading
-27.9 KB
Loading

0 commit comments

Comments
 (0)