Skip to content

Regression: undocumented change of behaviour in mpl 3.4.2 with axis ticks direction #20219

Closed

Description

@neutrinoceros

Bug report

Bug summary

Ticks direction set with Axes.tick_params used to be persistent but is now erased by Axes.cla().
Maybe this change is actually intended ? in any case I couldn't find a mention of it in your release notes so I'm considering it a bug for now.

Code for reproduction

I originally detected a regression in yt, see yt-project/yt#3256
I was able to reproduce the change of behaviour with the following minimal script

import matplotlib.pyplot as plt

from matplotlib import __version__ as mplver

fig, ax = plt.subplots()
ax.tick_params(direction="in")
ax.cla()
fig.savefig(f"/tmp/mpl_{mplver}_regr.jpg")

Actual outcome

This is with matplotlib 3.4.2

mpl_3 4 2_regr

Expected outcome

This is with matplotlib 3.4.1
mpl_3 4 1_regr

Matplotlib version

  • Operating system: OSX
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): see above
  • Matplotlib backend (print(matplotlib.get_backend())): MaxOSX
  • Python version: 3.9

installed from pypi with pip

Activity

  1. jklymak commented on May 13, 2021

    @jklymak
    Member

    This bisects to #20161 @timhoffm if you had a chance to take a look? It looks like resetting all the kwargs in clear was too aggressive.

  2. tacaswell commented on May 13, 2021

    @tacaswell
    Member

    I think there is a strong case that the 3.4.1 behavior was buggy (as ax.cla() should set the axes back to its "fresh" state).

    This is one of the fun things of working on a widely used library: all possible observed behavior eventually becomes a feature to at least one user (see https://xkcd.com/1172/)!

    If you want to have the default direction of the ticks be in I would use

    import matplotlib.pyplot as plt
    plt.rcParams['xtick.direction'] = plt.rcParams['ytick.direction'] = 'in'
  3. neutrinoceros commented on May 13, 2021

    @neutrinoceros
    ContributorAuthor

    I'm fine either way, though if you're considering it a bugfix I think it should be documented as such :-)

  4. neutrinoceros commented on Aug 5, 2021

    @neutrinoceros
    ContributorAuthor

    @jklymak @tacaswell is there any relevant change or discussion about this ? should the new behaviour just be regarded as the new standard onwards ?

  5. jklymak commented on Aug 5, 2021

    @jklymak
    Member

    I guess it depends on whether other tick params are persistent or not. Similarly other axes amd axis properties. If I change the face color does that reset in cla? I thought that cla simply removed any artists and reset any limits, but you could imagine it also scrubbing any axes styling.

  6. tacaswell commented on Aug 5, 2021

    @tacaswell
    Member

    @neutrinoceros I'm still pretty convinced that the ticks not getting re-set was a bug and ax.cla() should take it back to an identical state to as when it was created. This is in part because it is easy to document and understand ("it makes it like new!" is simpler than "It makes it like new except for....") and because we use self.cla() as part of the initialization process of Axes.

  7. neutrinoceros commented on Aug 5, 2021

    @neutrinoceros
    ContributorAuthor

    @tacaswell this makes sense to me. Should I move forward and open a PR to document this as the canonical/expected behaviour ?

  8. jklymak commented on Aug 5, 2021

    @jklymak
    Member
    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib as mpl
    
    fig, ax = plt.subplots()
    ax.set_facecolor('r')
    ax.cla()
    plt.show()

    shows a red axes, so I don't think its true that clearing the axes gives us a "new" axes; it clears the children.

  9. tacaswell commented on Aug 5, 2021

    @tacaswell
    Member

    Maybe we should document cla as

    Clears the Axes

    This will remove all of the children and reset many of the style parameters
    of the Axes and Axis.

    and also add a retro-active behavior change note to https://github.com/matplotlib/matplotlib/blob/master/doc/api/prev_api_changes/api_changes_3.4.2.rst

    If someone where to report Jody's example as a bug I would agree it was a bug. On the other had I bet the behavior has been like that forever and we do not want to wantonly break users.

  10. jklymak commented on Aug 6, 2021

    @jklymak
    Member

    I think we should specify which properties will be reset and not change them arbitrarily. I think "some properties" is too vague.

    Axes.cla does lots of stuff, much of which seems concerned with initial setup of the axes. But it does try to explicitly preserve a bunch of things as well.

  11. tacaswell commented on Aug 9, 2021

    @tacaswell
    Member

    I think we should specify which properties will be reset and not change them arbitrarily.

    You are right, but I do not like it.

  12. added this to the v3.4.3 milestone on Aug 11, 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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions