Skip to content

Grid disappear after pcolormesh apply #15600

Closed

Description

@AntSimi

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

Activity

  1. ImportanceOfBeingErnest commented on Nov 4, 2019

    @ImportanceOfBeingErnest
    Member

    The grid seems to be turned off deliberately

    self.grid(False)

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

  2. jklymak commented on Nov 4, 2019

    @jklymak
    Member

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

  3. anntzer commented on Nov 4, 2019

    @anntzer
    Contributor

    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.

  4. timhoffm commented on Nov 4, 2019

    @timhoffm
    Member

    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?

  5. Tillsten commented on Nov 5, 2019

    @Tillsten
    Contributor

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

  6. anntzer commented on Nov 5, 2019

    @anntzer
    Contributor

    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.

  7. timhoffm commented on Nov 5, 2019

    @timhoffm
    Member

    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.

  8. anntzer commented on Nov 5, 2019

    @anntzer
    Contributor

    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.

  9. jklymak commented on Nov 5, 2019

    @jklymak
    Member

    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

  10. timhoffm commented on Nov 5, 2019

    @timhoffm
    Member

    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.

  11. anntzer commented on Nov 5, 2019

    @anntzer
    Contributor

    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).

  12. timhoffm commented on Nov 5, 2019

    @timhoffm
    Member

    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.

  13. added this to the v3.5.0 milestone on May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions