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 2834743

Browse filesBrowse files
authored
Merge pull request #12359 from abhinuvpitale/abhinuvpitale-patch-issue12311
ENH: Add boolean support for axis()
2 parents 1a89250 + f3db0af commit 2834743
Copy full SHA for 2834743

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
@@ -1588,7 +1588,7 @@ def apply_aspect(self, position=None):
15881588
else:
15891589
self.set_xbound((x0, x1))
15901590

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

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

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

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

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

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

17181728
self.set_xlim([v[0], v[1]], emit=emit, auto=False)
17191729
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
@@ -6269,3 +6269,15 @@ def test_minor_accountedfor():
62696269
targetbb = mtransforms.Bbox.from_bounds(*targets[n])
62706270
assert_allclose(bbspines[n * 2].bounds, targetbb.bounds,
62716271
atol=1e-2)
6272+
6273+
6274+
@check_figures_equal(extensions=["png"])
6275+
def test_axis_bool_arguments(fig_test, fig_ref):
6276+
# Test if False and "off" give the same
6277+
fig_test.add_subplot(211).axis(False)
6278+
fig_ref.add_subplot(211).axis("off")
6279+
# Test if True after False gives the same as "on"
6280+
ax = fig_test.add_subplot(212)
6281+
ax.axis(False)
6282+
ax.axis(True)
6283+
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.