Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 1 commit into from
Oct 20, 2020
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 18, 2020

Remove the separate _gridOnMajor/_gridOnMinor attributes and store
visibility together with all other grid attributes in the
_major_tick_kw/_minor_tick_kw dicts under the "gridOn" key. This makes
it possible to update just that entry in Axis.grid.

Also, don't normalize b to True if len(kwargs) in Axes.grid:
we need to keep it as None, normalizing it only to True/False in
Axis.grid (which handles that just fine), so that Axis.grid can
handle the consistency checks between b and visible.

Closes #18758.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and pydocstyle<4 and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Remove the separate _gridOnMajor/_gridOnMinor attributes and store
visibility together with all other grid attributes in the
_major_tick_kw/_minor_tick_kw dicts under the "gridOn" key.  This makes
it possible to update just that entry in `Axis.grid`.

Also, don't normalize `b` to True `if len(kwargs)` in `Axes.grid`:
we need to keep it as `None`, normalizing it only to True/False in
`Axis.grid` (which handles that just fine), so that `Axis.grid` can
handle the consistency checks between `b` and `visible`.
@QuLogic
Copy link
Member

QuLogic commented Oct 19, 2020

That issue was a regression from 3.2.2. Is this entire change necessary to fix it? I'm trying to determine whether this whole PR would need to go back, or some smaller version only.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 20, 2020

I didn't know it was a regression, so I have no idea whether there's a simpler fix...
(I do think kill _gridOnMajor/_gridOnMinor is a good idea at least for the long term, though.)

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']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this toggle the value in _minor_tick_kw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_tick_params (called just below) does that.

"""
if len(kwargs):
if not b and b is not None: # something false-like but not None
Copy link
Member

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 to visible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b=None (== toggle) and visible=None (== False) behave differently. I think all these toggling APIs are pretty terrible, but breaking all the scripts in the world that do ax.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 deprecate b) though. Then the only case we'd break is people doing ax.grid() to switch off the grid when the grid is already on, which is probably much less common (and ax.grid(False) just seems much clearer). But let's keep that discussion for another time.

Copy link
Member

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.

@QuLogic QuLogic added this to the v3.3.3 milestone Oct 20, 2020
@QuLogic QuLogic merged commit d7fc51b into matplotlib:master Oct 20, 2020
@lumberbot-app
Copy link

lumberbot-app bot commented Oct 20, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.3.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 d7fc51b7d9adfcb537788b36d24ece420aa3f930
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #18769: Support `ax.grid(visible=<bool>)`.'
  1. Push to a named branch :
git push YOURFORK v3.3.x:auto-backport-of-pr-18769-on-v3.3.x
  1. Create a PR against branch v3.3.x, I would have named this PR:

"Backport PR #18769 on branch v3.3.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@Dapid
Copy link

Dapid commented Nov 26, 2020

This change has broken other packages. Is it really necessary to remove _gridOnMajor/_gridOnMinor?

@jklymak
Copy link
Member

jklymak commented Nov 26, 2020

Do we really have no public interface to check whether the grid is on? Downstream libraries are now replacing the private self.xaxis._gridOnMinor with the private self.xaxis._minor_tick_kw["gridOn"], which seems even worse.

@jklymak
Copy link
Member

jklymak commented Nov 26, 2020

It would be helpful if other packages open an issue if they are stuck using a private attribute to access information they need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using Axis.grid(visible=True) results in TypeError for multiple values for keyword argument
5 participants