-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support ax.grid(visible=<bool>)
.
#18769
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -790,10 +790,10 @@ def clear(self): | |
self.callbacks = cbook.CallbackRegistry() | ||
|
||
# whether the grids are on | ||
self._gridOnMajor = ( | ||
self._major_tick_kw['gridOn'] = ( | ||
mpl.rcParams['axes.grid'] and | ||
mpl.rcParams['axes.grid.which'] in ('both', 'major')) | ||
self._gridOnMinor = ( | ||
self._minor_tick_kw['gridOn'] = ( | ||
mpl.rcParams['axes.grid'] and | ||
mpl.rcParams['axes.grid.which'] in ('both', 'minor')) | ||
|
||
|
@@ -1398,7 +1398,6 @@ def get_major_ticks(self, numticks=None): | |
# Update the new tick label properties from the old. | ||
tick = self._get_tick(major=True) | ||
self.majorTicks.append(tick) | ||
tick.gridline.set_visible(self._gridOnMajor) | ||
self._copy_tick_props(self.majorTicks[0], tick) | ||
|
||
return self.majorTicks[:numticks] | ||
|
@@ -1412,7 +1411,6 @@ def get_minor_ticks(self, numticks=None): | |
# Update the new tick label properties from the old. | ||
tick = self._get_tick(major=False) | ||
self.minorTicks.append(tick) | ||
tick.gridline.set_visible(self._gridOnMinor) | ||
self._copy_tick_props(self.minorTicks[0], tick) | ||
|
||
return self.minorTicks[:numticks] | ||
|
@@ -1437,32 +1435,37 @@ def grid(self, b=None, which='major', **kwargs): | |
Define the line properties of the grid, e.g.:: | ||
|
||
grid(color='r', linestyle='-', linewidth=2) | ||
|
||
""" | ||
if len(kwargs): | ||
if not b and b is not None: # something false-like but not None | ||
if b is not None: | ||
if 'visible' in kwargs and bool(b) != bool(kwargs['visible']): | ||
raise ValueError( | ||
"'b' and 'visible' specify inconsistent grid visibilities") | ||
if kwargs and not b: # something false-like but not None | ||
cbook._warn_external('First parameter to grid() is false, ' | ||
'but line properties are supplied. The ' | ||
'grid will be enabled.') | ||
b = True | ||
b = True | ||
which = which.lower() | ||
_api.check_in_list(['major', 'minor', 'both'], which=which) | ||
gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()} | ||
if 'grid_visible' in gridkw: | ||
forced_visibility = True | ||
gridkw['gridOn'] = gridkw.pop('grid_visible') | ||
else: | ||
forced_visibility = False | ||
|
||
if which in ['minor', 'both']: | ||
if b is None: | ||
self._gridOnMinor = not self._gridOnMinor | ||
else: | ||
self._gridOnMinor = b | ||
self.set_tick_params(which='minor', gridOn=self._gridOnMinor, | ||
**gridkw) | ||
if b is None and not forced_visibility: | ||
gridkw['gridOn'] = not self._minor_tick_kw['gridOn'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this toggle the value in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set_tick_params (called just below) does that. |
||
elif b is not None: | ||
gridkw['gridOn'] = b | ||
self.set_tick_params(which='minor', **gridkw) | ||
if which in ['major', 'both']: | ||
if b is None: | ||
self._gridOnMajor = not self._gridOnMajor | ||
else: | ||
self._gridOnMajor = b | ||
self.set_tick_params(which='major', gridOn=self._gridOnMajor, | ||
**gridkw) | ||
if b is None and not forced_visibility: | ||
gridkw['gridOn'] = not self._major_tick_kw['gridOn'] | ||
elif b is not None: | ||
gridkw['gridOn'] = b | ||
self.set_tick_params(which='major', **gridkw) | ||
self.stale = True | ||
|
||
def update_units(self, data): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we instead rename
b
tovisible
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b=None
(== toggle) andvisible=None
(== False) behave differently. I think all these toggling APIs are pretty terrible, but breaking all the scripts in the world that doax.grid()
to toggle the grid on is just not worth it.I guess we could aim to have the end API be
def grid(visible=True, ...):
(and deprecateb
) though. Then the only case we'd break is people doingax.grid()
to switch off the grid when the grid is already on, which is probably much less common (andax.grid(False)
just seems much clearer). But let's keep that discussion for another time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, it's worse than I thought.