Skip to content

Grid disappear after pcolormesh apply #15600

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

Closed
AntSimi opened this issue Nov 4, 2019 · 12 comments · Fixed by #15604
Closed

Grid disappear after pcolormesh apply #15600

AntSimi opened this issue Nov 4, 2019 · 12 comments · Fixed by #15604
Milestone

Comments

@AntSimi
Copy link

AntSimi commented Nov 4, 2019

Bug report

Bug summary

Grid disappear after pcolormesh apply
toto

Code for reproduction

from matplotlib import pyplot as plt
import numpy as np
ax = plt.subplot(111)
ax.grid(True)
ax.pcolormesh(np.arange(7), np.arange(7), np.random.randn(6,6))
ax.set_xlim(-1,7)
plt.show()

Expected outcome

Grid must be visible, but if you apply a pcolormesh after to set grid to True, grid disapear?

Matplotlib version

  • Operating system: Ubuntu
  • Matplotlib version: 3.1.1
  • Matplotlib backend : Qt4Agg
  • Python version: 3.7.4

I install library with conda with no options:
conda install matplotlib

@ImportanceOfBeingErnest
Copy link
Member

The grid seems to be turned off deliberately

self.grid(False)

I don't know if there is any specific reason for that?

@jklymak
Copy link
Member

jklymak commented Nov 4, 2019

Weird. It’s been like that for 14 years though, so may be hard to change?

@anntzer
Copy link
Contributor

anntzer commented Nov 4, 2019

Looks like pcolor() does the same, and has basically always done so.
It's probably actually not too hard to change that (and I think removing that line makes sense): one can check before the call to grid(False) whether the grid is on (which would only happen if explicitly set earlier in the code and then the user relying on pcolor(mesh)() unsetting it...) and if so emit a deprecationwarning asking to unset the grid first.

@timhoffm
Copy link
Member

timhoffm commented Nov 4, 2019

Could it be that this serves the purpose of overriding rcParams[axes.grid.*] settings for these plots? By default, a style might have grid lines, but they don't make sense for false-color plots.

Anyway should imshow() have the same behavior?

@Tillsten
Copy link
Contributor

Tillsten commented Nov 5, 2019

As a suggestion, maybe add another rcParams['axes.auto_disable'] ?

@anntzer
Copy link
Contributor

anntzer commented Nov 5, 2019

Could it be that this serves the purpose of overriding rcParams[axes.grid.*] settings for these plots? By default, a style might have grid lines, but they don't make sense for false-color plots.

Actually I occasionally do want grids on my images.

As a suggestion, maybe add another rcParams['axes.auto_disable'] ?

In that case I would suggest just disabling the grid yourself with grid(False) (or modifying the style to unset rcParams["axes.grid.*"]); I don't think every possible arrangement needs to be doable via rcParams.

@timhoffm
Copy link
Member

timhoffm commented Nov 5, 2019

Actually I occasionally do want grids on my images.

Agreed.

I don't think every possible arrangement needs to be doable via rcParams.

Agreed.

However, we need the possibility to have a style with gridded regular axes, but no grids on false-color plots. That's a reasonable combination of defaults. Moreover, that's how current styles are rendered, and we cannot request ggplot-style or seaborn-style users to add grid(False) to all their false-color plots manually.

Since an Axes does not know it will be filled with a false-color plot at creation time, I don't think there is a way around calling grid(False) within pcolormesh and similar. The only question is if it's called unconditionally, or if we add kwargs and/or rcParams to control it.

@anntzer
Copy link
Contributor

anntzer commented Nov 5, 2019

we cannot request ggplot-style or seaborn-style users to add grid(False) to all their false-color plots manually.

[...] if we add kwargs and/or rcParams to control it.

If we're going to make the user add a kwarg to each call I don't see how that's better than requesting that the user calls grid(False) first.

Also note that imshow() doesn't have that behavior, even though it's arguably in the same category of plots.

@jklymak
Copy link
Member

jklymak commented Nov 5, 2019

I don’t think any individual artists should set axes properties. If it weren’t for back compatibility concerns I’d vote to change this

@timhoffm
Copy link
Member

timhoffm commented Nov 5, 2019

If we're going to make the user add a kwarg to each call I don't see how that's better than requesting that the user calls grid(False) first.

For backward compatibility, the default would of course stay to deactivate the grid.

@anntzer
Copy link
Contributor

anntzer commented Nov 5, 2019

My point is that this can actually be changed with a proper deprecation transition (check whether the grid was set, and if so, warn that pcolormesh won't unset it for you anymore in the future).

@timhoffm
Copy link
Member

timhoffm commented Nov 5, 2019

I don’t think any individual artists should set axes properties.

It's the pcolormesh() method, not the artist. There's other precedence, e.g. imshow sets the aspect. I believe that some plotting functions may modify the axes by default to adapt it to the intention of the plot type.

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

Successfully merging a pull request may close this issue.

7 participants