8000 set_ticks([single_tick]) should also expand view limits. · matplotlib/matplotlib@5ab9436 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ab9436

Browse files
committed
set_ticks([single_tick]) should also expand view limits.
Previously, the single-tick case would not perform expansion. (Curiously, the `len > 1` check was added in 0b48047 to fix inversion handling, and then cb5cab4 tried another fix apparently for the same problem (by making set_view_limits maintain preexisting inversions).)
1 parent a080696 commit 5ab9436

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/matplotlib/axis.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,13 +1801,10 @@ def _set_tick_locations(self, ticks, *, minor=False):
18011801
break
18021802
else:
18031803
shared = [self]
1804-
for axis in shared:
1805-
if len(ticks) > 1:
1806-
xleft, xright = axis.get_view_interval()
1807-
if xright > xleft:
1808-
axis.set_view_interval(min(ticks), max(ticks))
1809-
else:
1810-
axis.set_view_interval(max(ticks), min(ticks))
1804+
if len(ticks):
1805+
for axis in shared:
1806+
# set_view_interval maintains any preexisting inversion.
1807+
axis.set_view_interval(min(ticks), max(ticks))
18111808
self.axes.stale = True
18121809
if minor:
18131810
self.set_minor_locator(mticker.FixedLocator(ticks))

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6808,6 +6808,8 @@ def test_set_ticks_inverted():
68086808
ax.invert_xaxis()
68096809
ax.set_xticks([.3, .7])
68106810
assert ax.get_xlim() == (1, 0)
6811+
ax.set_xticks([-1])
6812+
assert ax.get_xlim() == (1, -1)
68116813

68126814

68136815
def test_aspect_nonlinear_adjustable_box():

0 commit comments

Comments
 (0)
0