8000 Argument checking for grid() by timhoffm · Pull Request #11784 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Argument checking for grid() #11784

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
Aug 20, 2018
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
7 changes: 5 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2716,9 +2716,12 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
elif b is not None:
b = _string_to_bool(b)

if axis == 'x' or axis == 'both':
if axis not in ['x', 'y', 'both']:
raise ValueError("The argument 'axis' must be one of 'x', 'y' or "
"'both'.")
if axis in ['x', 'both']:
self.xaxis.grid(b, which=which, **kwargs)
if axis == 'y' or axis == 'both':
if axis in ['y', 'both']:
self.yaxis.grid(b, which=which, **kwargs)

def ticklabel_format(self, *, axis='both', style='', scilimits=None,
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,17 @@ def grid(self, b=None, which='major', **kwargs):

"""
if len(kwargs):
if not b and b is not None: # something false-like but not None
warnings.warn('First parameter to grid() is false, but line '
'properties are supplied. The grid will be '
'enabled.')
b = True
which = which.lower()
if which not in ['major', 'minor', 'both']:
raise ValueError("The argument 'which' must be one of 'major', "
"'minor' or 'both'.")
gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()}

if which in ['minor', 'both']:
if b is None:
self._gridOnMinor = not self._gridOnMinor
Expand Down
0