8000 Support passing spine bounds as single tuple. · alexrudy/matplotlib@e06d2bc · GitHub
[go: up one dir, main page]

Skip to content

Commit e06d2bc

Browse files
committed
Support passing spine bounds as single tuple.
For consistency with Axes.set_xlim. There's no test whatsoever for Spine.set_bounds, but we can at least exercise that code path in the examples.
1 parent 385dd94 commit e06d2bc

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

examples/ticks_and_spines/spines_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
ax.set_yticks([-1, 0, 1])
2828

2929
# Only draw spine between the y-ticks
30-
ax.spines['left'].set_bounds(-1, 1)
30+
ax.spines['left'].set_bounds((-1, 1))
3131
# Hide the right and top spines
3232
ax.spines['right'].set_visible(False)
3333
ax.spines['top'].set_visible(False)

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
31063106
The left xlim in data coordinates. Passing *None* leaves the
31073107
limit unchanged.
31083108
3109-
The left and right xlims may be passed as the tuple
3109+
The left and right xlims may also be passed as the tuple
31103110
(*left*, *right*) as the first positional argument (or as
31113111
the *left* keyword argument).
31123112
@@ -3486,7 +3486,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
34863486
The bottom ylim in data coordinates. Passing *None* leaves the
34873487
limit unchanged.
34883488
3489-
The bottom and top ylims may be passed as the tuple
3489+
The bottom and top ylims may also be passed as the tuple
34903490
(*bottom*, *top*) as the first positional argument (or as
34913491
the *bottom* keyword argument).
34923492

lib/matplotlib/spines.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,33 @@ def get_spine_transform(self):
534534
else:
535535
raise ValueError("unknown spine_transform type: %s" % what)
536536

537-
def set_bounds(self, low, high):
538-
"""Set the bounds of the spine."""
537+
def set_bounds(self, low=None, high=None):
538+
"""
539+
Set the spine bounds.
540+
541+
.. ACCEPTS: (low: float, high: float)
542+
543+
Parameters
544+
----------
545+
low : scalar, optional
546+
The lower spine bound. Passing *None* leaves the limit unchanged.
547+
548+
The bounds may also be passed as the tuple (*low*, *high*) as the
549+
first positional argument.
550+
551+
high : scalar, optional
552+
The higher spine bound. Passing *None* leaves the limit unchanged.
553+
"""
539554
if self.spine_type == 'circle':
540555
raise ValueError(
541556
'set_bounds() method incompatible with circular spines')
557+
if high is None and np.iterable(low):
558+
low, high = low
559+
old_low, old_high = self.get_bounds() or (None, None)
560+
if low is None:
561+
low = old_low
562+
if high is None:
563+
high = old_high
542564
self._bounds = (low, high)
543565
self.stale = True
544566

0 commit comments

Comments
 (0)
0