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

Skip to content

Commit 10ea1eb

Browse files
committed
feat: add option to force sticky_edges
1 parent 4735755 commit 10ea1eb

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6788,13 +6788,15 @@ def stairs(self, values, edges=None, *,
67886788
orientation=orientation,
67896789
fill=fill,
67906790
**kwargs)
6791-
self.add_patch(patch)
6791+
67926792
if baseline is None:
67936793
baseline = 0
67946794
if orientation == 'vertical':
67956795
patch.sticky_edges.y.append(np.min(baseline))
67966796
else:
67976797
patch.sticky_edges.x.append(np.min(baseline))
6798+
self.force_sticky_edges = True
6799+
self.add_patch(patch)
67986800
self._request_autoscale_view()
67996801
return patch
68006802

lib/matplotlib/axes/_base.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ def cla(self):
11411141
self._ymargin = mpl.rcParams['axes.ymargin']
11421142
self._tight = None
11431143
self._use_sticky_edges = True
1144+
self._force_sticky_edges = False
11441145
self._update_transScale() # needed?
11451146

11461147
self._get_lines = _process_plot_var_args(self)
@@ -2352,6 +2353,29 @@ def use_sticky_edges(self, b):
23522353
self._use_sticky_edges = bool(b)
23532354
# No effect until next autoscaling, which will mark the axes as stale.
23542355

2356+
@property
2357+
def force_sticky_edges(self):
2358+
"""
2359+
When autoscaling, whether to enforce `Artist.sticky_edges`
2360+
values.
2361+
2362+
Default is ``False``.
2363+
2364+
By default, when ``sticky_edges`` are present the tighter
2365+
marging is used between the "automatic" and the "sticky".
2366+
Setting this to ``True`` forces the use of the specified margins,
2367+
even if sticky_edge value is far away from datalim.
2368+
2369+
The changing this property does not change the plot until
2370+
`autoscale` or `autoscale_view` is called.
2371+
"""
2372+
return self._force_sticky_edges
2373+
2374+
@force_sticky_edges.setter
2375+
def force_sticky_edges(self, b):
2376+
self._force_sticky_edges = bool(b)
2377+
# No effect until next autoscaling, which will mark the axes as stale.
2378+
23552379
def set_xmargin(self, m):
23562380
"""
23572381
Set padding of X data limits prior to autoscaling.
@@ -2644,10 +2668,11 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
26442668
x0, x1 = inverse_trans.transform([x0t - delta, x1t + delta])
26452669

26462670
# Apply sticky bounds.
2671+
_f = self._force_sticky_edges
26472672
if x0bound is not None:
2648-
x0 = max(x0, x0bound)
2673+
x0 = max(x0, x0bound) if not _f else x0bound
26492674
if x1bound is not None:
2650-
x1 = min(x1, x1bound)
2675+
x1 = min(x1, x1bound) if not _f else x1bound
26512676

26522677
if not self._tight:
26532678
x0, x1 = locator.view_limits(x0, x1)

0 commit comments

Comments
 (0)