Skip to content

zorder=None not properly handled #9785

Closed

Description

@jsh9

Matplotlib developers:

I have some feature requests and/or questions about the grid behaviors in matplotlib v2.0+:

(1) Is it possible to set the default grid line to even lighter gray, and even thinner line width? Just like the style in MATLAB? The current new Matplotlib defaults generate grid lines that look too pronounced.

In fact, when using Matplotlib 2.0+, I always use plt.grid(ls=':') instead of just plt.grid(). It looks much better.

(2) The zorder behavior, if set to None, is undefined, or at least not documented clearly.

For example, I tried the following codes respectively:

plt.figure(); plt.plot([0,1],[0,1],lw=10); plt.grid()
plt.figure(); plt.plot([0,1],[0,1],lw=10,zorder=None); plt.grid()
plt.figure(); plt.plot([0,1],[0,1],lw=10); plt.grid(zorder=None)
plt.figure(); plt.plot([0,1],[0,1],lw=10,zorder=None); plt.grid(zorder=None)

and I am getting confusing results.

There is indeed some needs to pass None to zorder, especially when designing wrapper functions where zorder sometimes needs to be specified by the user, and sometimes doesn't.

Activity

  1. anntzer commented on Nov 14, 2017

    @anntzer
    Contributor

    xref #9094 re: zorder.

  2. jsh9 commented on Nov 14, 2017

    @jsh9
    Author

    I tried this:

    plt.figure(); ax=plt.axes(); plt.plot([0,1],[0,1],lw=10,zorder=None); plt.grid(); ax.set_axisbelow(True);

    But the line is still below the grids. Apparently zorder=None within plt.plot() sends the line to the most bottom layer...

    Shouldn't zorder=None within plt.plot() just work as if we did not invoke this argument at all?

  3. anntzer commented on Nov 14, 2017

    @anntzer
    Contributor

    Non-numeric zorder errors out on Py3 because they can't, well, be compared with numbers.
    On Py2 None is sorted before numbers hence the observed behavior. I honestly don't care enough about Py2 anymore to fix that...

  4. ImportanceOfBeingErnest commented on Nov 15, 2017

    @ImportanceOfBeingErnest
    Member

    @anntzer I really hope you do care about python 2 still. According to this statics
    image
    it is still used more than python 3. Also see here.

    So there should be a defined behaviour of zorder=None, independent on the version of python in use. Why not simply throw an error as well?

  5. jklymak commented on Nov 15, 2017

    @jklymak
    Member

    @anntzer wasn't saying not to fix it. He was saying he wasn't going to fix it. I'm sure a sensible PR would be welcome. But I think the point is that zorder=None is undefined, so don't do that.

  6. jsh9 commented on Nov 15, 2017

    @jsh9
    Author

    I guess there is some need to update the documentation containing zorder, adding a note for Python 2 users in the documentation. Or Matplotlib can raise a warning message when Python 2 users try to set zorder=None

  7. WeatherGod commented on Nov 15, 2017

    @WeatherGod
    Member
  8. anntzer commented on Nov 15, 2017

    @anntzer
    Contributor

    To be clear: I will obviously not prevent anyone from fixing the issue on py2.

  9. added this to the v2.1.1 milestone on Nov 15, 2017
  10. tacaswell commented on Nov 15, 2017

    @tacaswell
    Member

    We are committed to python2 support through mpl2.2 (early next year) and bug fixes on that branch until 2020. The level of back-ported support to 2.2.x will depend on volunteer interest, but I am personally committed to does-not-import / segfault type bug fixes.

    That said, this is not a python2/python3 bug, the issue is that zorder=None is not being properly handled in any version. It should, as @WeatherGod says, mean 'do the default thing' as the OP expected.

    @jsh9 You can use rcparams / style sheets to set the default gridline style and color https://matplotlib.org/users/customizing.html

  11. jsh9 commented on Nov 15, 2017

    @jsh9
    Author

    @tacaswell Thanks for the comments.

    Yes, I am aware of rcparams or style sheets, but it is somewhat cumbersome (for example, I have to revert the styles back for other users of my scripts, because I don't want to mess up their flavor of plotting styles).

    The reason I'm bring this issue up is that I think the Matplotlib default style leaves some aesthetic room to be desired. And making the default style more pleasing can attract more potential users. (Of course, this is a somewhat subjective discussion, and I am open to hearing other people's opinion about this :-)

  12. jklymak commented on Nov 15, 2017

    @jklymak
    Member

    I think thats why there are style files - so you can set the grid however you want. The default styles were just changed for 2.0, presumably to someone's aesthetic delight. So my guess is that they won't be reconsidered again for a while.

  13. changed the title [-]Default grid behaviors in matplotlib v2.0+[/-] [+]`plt.grid` does not handle `zorder=None` properly[/+] on Nov 15, 2017
  14. tacaswell commented on Nov 15, 2017

    @tacaswell
    Member

    The style context managers can be helpful for ensure the style gets reverted.

    Changed the issue title to better reflect the bug that needs to be fixed.

  15. jsh9 commented on Nov 15, 2017

    @jsh9
    Author

    Not only plt.grid does not handle zorder=None properly, but also plt.plot and maybe other functions, am I correct?

  16. tacaswell commented on Nov 16, 2017

    @tacaswell
    Member

    @jsh9 🐑 did not read carefully enough or test

  17. changed the title [-]`plt.grid` does not handle `zorder=None` properly[/-] [+] `zorder=None` not properly handled[/+] on Nov 16, 2017
  18. added a commit that references this issue on Nov 16, 2017
    ed02d72
  19. afvincent commented on Nov 17, 2017

    @afvincent
    Contributor

    @tacaswell Should this issue be closed since #9793 was merged?

  20. tacaswell commented on Nov 17, 2017

    @tacaswell
    Member

    It will auto-close when the merge up to master happens

  21. jklymak commented on Nov 17, 2017

    @jklymak
    Member

    But isn't #9793 merged already? I'll close, and re-open if you meant something else...

  22. afvincent commented on Nov 17, 2017

    @afvincent
    Contributor

    @jklymak Well I think that @tacaswell is used to target “the right branch” for his PRs ^^. For example, #9793 was not merged on the master branch, so this might be the explanation.

  23. jklymak commented on Nov 17, 2017

    @jklymak
    Member

    Ohhhh. I see. He merged it into 2.1.x. My mistake...

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