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

Skip to content

Commit b367d82

Browse files
committed
feat: add option to force sticky_edges
1 parent dc202b4 commit b367d82

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6799,13 +6799,15 @@ def stairs(self, values, edges=None, *,
67996799
orientation=orientation,
68006800
fill=fill,
68016801
**kwargs)
6802-
self.add_patch(patch)
6802+
68036803
if baseline is None:
68046804
baseline = 0
68056805
if orientation == 'vertical':
68066806
patch.sticky_edges.y.append(np.min(baseline))
68076807
else:
68086808
patch.sticky_edges.x.append(np.min(baseline))
6809+
self.force_sticky_edges = True
6810+
self.add_patch(patch)
68096811
self._request_autoscale_view()
68106812
return patch
68116813

lib/matplotlib/axes/_base.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ def cla(self):
11341134
self._ymargin = mpl.rcParams['axes.ymargin']
11351135
self._tight = None
11361136
self._use_sticky_edges = True
1137+
self._force_sticky_edges = False
11371138
self._update_transScale() # needed?
11381139

11391140
self._get_lines = _process_plot_var_args(self)
@@ -2328,6 +2329,29 @@ def use_sticky_edges(self, b):
23282329
self._use_sticky_edges = bool(b)
23292330
# No effect until next autoscaling, which will mark the axes as stale.
23302331

2332+
@property
2333+
def force_sticky_edges(self):
2334+
"""
2335+
When autoscaling, whether to enforce `Artist.sticky_edges`
2336+
values.
2337+
2338+
Default is ``False``.
2339+
2340+
By default, when ``sticky_edges`` are present the tighter
2341+
marging is used between the "automatic" and the "sticky".
2342+
Setting this to ``True`` forces the use of the specified margins,
2343+
even if sticky_edge value is far away from datalim.
2344+
2345+
The changing this property does not change the plot until
2346+
`autoscale` or `autoscale_view` is called.
2347+
"""
2348+
return self._force_sticky_edges
2349+
2350+
@use_sticky_edges.setter
2351+
def force_sticky_edges(self, b):
2352+
self._force_sticky_edges = bool(b)
2353+
# No effect until next autoscaling, which will mark the axes as stale.
2354+
23312355
def set_xmargin(self, m):
23322356
"""
23332357
Set padding of X data limits prior to autoscaling.
@@ -2571,7 +2595,6 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
25712595

25722596
def handle_single_axis(scale, autoscaleon, shared_axes, interval,
25732597
minpos, axis, margin, stickies, set_bound):
2574-
25752598
if not (scale and autoscaleon):
25762599
return # nothing to do...
25772600

@@ -2620,11 +2643,11 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
26202643
x0, x1 = inverse_trans.transform([x0t - delta, x1t + delta])
26212644

26222645
# Apply sticky bounds.
2646+
_f = self._force_sticky_edges
26232647
if x0bound is not None:
2624-
x0 = max(x0, x0bound)
2648+
x0 = max(x0, x0bound) if not _f else x0bound
26252649
if x1bound is not None:
2626-
x1 = min(x1, x1bound)
2627-
2650+
x1 = min(x1, x1bound) if not _f else x1bound
26282651
if not self._tight:
26292652
x0, x1 = locator.view_limits(x0, x1)
26302653
set_bound(x0, x1)

0 commit comments

Comments
 (0)