Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e42b813

Browse filesBrowse files
authored
Merge pull request #13597 from meeseeksmachine/auto-backport-of-pr-12359-on-v3.1.x
Backport PR #12359 on branch v3.1.x (ENH: Add boolean support for axis())
2 parents edc0632 + 6fdc027 commit e42b813
Copy full SHA for e42b813

File tree

Expand file treeCollapse file tree

3 files changed

+35
-13
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+35
-13
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+21-11Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ def apply_aspect(self, position=None):
15891589
else:
15901590
self.set_xbound((x0, x1))
15911591

1592-
def axis(self, *v, **kwargs):
1592+
def axis(self, *args, **kwargs):
15931593
"""
15941594
Convenience method to get or set some axis properties.
15951595
@@ -1606,14 +1606,15 @@ def axis(self, *v, **kwargs):
16061606
The axis limits to be set. Either none or all of the limits must
16071607
be given.
16081608
1609-
option : str
1610-
Possible values:
1609+
option : bool or str
1610+
If a bool, turns axis lines and labels on or off. If a string,
1611+
possible values are:
16111612
16121613
======== ==========================================================
16131614
Value Description
16141615
======== ==========================================================
1615-
'on' Turn on axis lines and labels.
1616-
'off' Turn off axis lines and labels.
1616+
'on' Turn on axis lines and labels. Same as ``True``.
1617+
'off' Turn off axis lines and labels. Same as ``False``.
16171618
'equal' Set equal scaling (i.e., make circles circular) by
16181619
changing axis limits.
16191620
'scaled' Set equal scaling (i.e., make circles circular) by
@@ -1642,15 +1643,15 @@ def axis(self, *v, **kwargs):
16421643
matplotlib.axes.Axes.set_ylim
16431644
"""
16441645

1645-
if len(v) == len(kwargs) == 0:
1646+
if len(args) == len(kwargs) == 0:
16461647
xmin, xmax = self.get_xlim()
16471648
ymin, ymax = self.get_ylim()
16481649
return xmin, xmax, ymin, ymax
16491650

16501651
emit = kwargs.get('emit', True)
16511652

1652-
if len(v) == 1 and isinstance(v[0], str):
1653-
s = v[0].lower()
1653+
if len(args) == 1 and isinstance(args[0], str):
1654+
s = args[0].lower()
16541655
if s == 'on':
16551656
self.set_axis_on()
16561657
elif s == 'off':
@@ -1695,7 +1696,7 @@ def axis(self, *v, **kwargs):
16951696
return xmin, xmax, ymin, ymax
16961697

16971698
try:
1698-
v[0]
1699+
args[0]
16991700
except IndexError:
17001701
xmin = kwargs.get('xmin', None)
17011702
xmax = kwargs.get('xmax', None)
@@ -1712,9 +1713,18 @@ def axis(self, *v, **kwargs):
17121713
ymin, ymax = self.set_ylim(ymin, ymax, emit=emit, auto=auto)
17131714
return xmin, xmax, ymin, ymax
17141715

1715-
v = v[0]
1716+
v = args[0]
1717+
if isinstance(v, bool):
1718+
if v:
1719+
self.set_axis_on()
1720+
else:
1721+
self.set_axis_off()
1722+
xmin, xmax = self.get_xlim()
1723+
ymin, ymax = self.get_ylim()
1724+
return xmin, xmax, ymin, ymax
1725+
17161726
if len(v) != 4:
1717-
raise ValueError('v must contain [xmin xmax ymin ymax]')
1727+
raise ValueError('args must contain [xmin xmax ymin ymax]')
17181728

17191729
self.set_xlim([v[0], v[1]], emit=emit, auto=False)
17201730
self.set_ylim([v[2], v[3]], emit=emit, auto=False)

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,8 +2393,8 @@ def axhspan(ymin, ymax, xmin=0, xmax=1, **kwargs):
23932393

23942394
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
23952395
@docstring.copy(Axes.axis)
2396-
def axis(*v, **kwargs):
2397-
return gca().axis(*v, **kwargs)
2396+
def axis(*args, **kwargs):
2397+
return gca().axis(*args, **kwargs)
23982398

23992399

24002400
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6270,3 +6270,15 @@ def test_minor_accountedfor():
62706270
targetbb = mtransforms.Bbox.from_bounds(*targets[n])
62716271
assert_allclose(bbspines[n * 2].bounds, targetbb.bounds,
62726272
atol=1e-2)
6273+
6274+
6275+
@check_figures_equal(extensions=["png"])
6276+
def test_axis_bool_arguments(fig_test, fig_ref):
6277+
# Test if False and "off" give the same
6278+
fig_test.add_subplot(211).axis(False)
6279+
fig_ref.add_subplot(211).axis("off")
6280+
# Test if True after False gives the same as "on"
6281+
ax = fig_test.add_subplot(212)
6282+
ax.axis(False)
6283+
ax.axis(True)
6284+
fig_ref.add_subplot(212).axis("on")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.