8000 ENH: Add boolean support for axis() by abhinuvpitale · Pull Request #12359 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add boolean support for axis() #12359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions lib/matplotlib/axes/_base.py
< 10000 td id="diff-eab8def55235f317e1ea06840d82467044586af2a7f9ec994356a14f70509b72R1615" data-line-number="1615" class="blob-num blob-num-addition js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ def apply_aspect(self, position=None):
else:
self.set_xbound((x0, x1))

def axis(self, *v, **kwargs):
def axis(self, *args, **kwargs):
"""
Convenience method to get or set some axis properties.

Expand All @@ -1605,14 +1605,15 @@ def axis(self, *v, **kwargs):
The axis limits to be set. Either none or all of the limits must
be given.

option : str
Possible values:
option : bool or str
If a bool, turns axis lines and labels on or off. If a string,
possible values are:

======== ==========================================================
Value Description
======== ==========================================================
'on' Turn on axis lines and labels.
'off' Turn off axis lines and labels.
'on' Turn on axis lines and labels. Same as ``True``.
'off' Turn off axis lines and labels. Same as ``False``.
'equal' Set equal scaling (i.e., make circles circular) by
changing axis limits.
'scaled' Set equal scaling (i.e., make circles circular) by
Expand Down Expand Up @@ -1641,15 +1642,15 @@ def axis(self, *v, **kwargs):
matplotlib.axes.Axes.set_ylim
"""

if len(v) == len(kwargs) == 0:
if len(args) == len(kwargs) == 0:
xmin, xmax = self.get_xlim()
ymin, ymax = self.get_ylim()
return xmin, xmax, ymin, ymax

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

if len(v) == 1 and isinstance(v[0], str):
s = v[0].lower()
if len(args) == 1 and isinstance(args[0], str):
s = args[0].lower()
if s == 'on':
self.set_axis_on()
elif s == 'off':
Expand Down Expand Up @@ -1694,7 +1695,7 @@ def axis(self, *v, **kwargs):
return xmin, xmax, ymin, ymax

try:
v[0]
args[0]
except IndexError:
xmin = kwargs.get('xmin', None)
xmax = kwargs.get('xmax', None)
Expand All @@ -1711,9 +1712,18 @@ def axis(self, *v, **kwargs):
ymin, ymax = self.set_ylim(ymin, ymax, emit=emit, auto=auto)
return xmin, xmax, ymin, ymax

v = v[0]
v = args[0]
if isinstance(v, bool):
if v:
self.set_axis_on()
else:
self.set_axis_off()
xmin, xmax = self.get_xlim()
ymin, ymax = self.get_ylim()
return xmin, xmax, ymin, ymax

if len(v) != 4:
raise ValueError('v must contain [xmin xmax ymin ymax]')
raise ValueError('args must contain [xmin xmax ymin ymax]')

self.set_xlim([v[0], v[1]], emit=emit, auto=False)
self.set_ylim([v[2], v[3]], emit=emit, auto=False)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,8 +2393,8 @@ def axhspan(ymin, ymax, xmin=0, xmax=1, **kwargs):

# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@docs AFA3 tring.copy(Axes.axis)
def axis(*v, **kwargs):
return gca().axis(*v, **kwargs)
def axis(*args, **kwargs):
return gca().axis(*args, **kwargs)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6269,3 +6269,15 @@ def test_minor_accountedfor():
targetbb = mtransforms.Bbox.from_bounds(*targets[n])
assert_allclose(bbspines[n * 2].bounds, targetbb.bounds,
atol=1e-2)


@check_figures_equal(extensions=["png"])
def test_axis_bool_arguments(fig_test, fig_ref):
# Test if False and "off" give the same
fig_test.add_subplot(211).axis(False)
fig_ref.add_subplot(211).axis("off")
# Test if True after False gives the same as "on"
ax = fig_test.add_subplot(212)
ax.axis(False)
ax.axis(True)
fig_ref.add_subplot(212).axis("on")
0