Skip to content

Toggling visibility of axis tick labels causes their destruction #16197

Open

Description

@TheAngulion

Toggling the visibility of the axis tick labels via set_visible(False) can lead to their outright destruction, see here. According to @ImportanceOfBeingErnest, this issue is related to #10088.

I include a minimal code fragment that demonstrates the problem.

Code for reproduction

from matplotlib import pyplot as plt
plt.plot([0, 1], [8, 6])
ax = plt.gca()
yticks = ax.get_yticklabels()
print(yticks)
for tick in yticks:
    tick.set_visible(False)

print(ax.get_yticklabels())

Actual outcome

<a list of 11 Text yticklabel objects>
<a list of 0 Text yticklabel objects>

Expected outcome

The snippet shows that the y tick labels are destructed after setting their visibility to False. One can restore them by issuing:

ax.yaxis.set_tick_params(labelleft=True)

This issue first occurred on matplotlib 3.1.2 but not on the previous version (which I believe was 3.0.x).

Matplotlib version

  • Operating system: Win10 Pro 64bit
  • Matplotlib version: 3.1.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.3

Python was installed via WinPython; Matplotlib was manually upgraded to v3.1.2.

Activity

  1. timhoffm commented on Jan 12, 2020

    @timhoffm
    Member

    This seems sort of intentional:

    labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]

    @anntzer can you comment on that? This seems like a regression from #10088.

    Anyway, if this is the desired behavior, we should add a note in the tick label getter methods.

  2. anntzer commented on Jan 13, 2020

    @anntzer
    Contributor

    Previously ticks whose label1On attribute was set to False were excluded (per 525dcef#diff-52127080e2783464f529df684d82d476L1239), so I just remapped the behavior to get_visible(), as that was the point of #10088. So it's intended, but really more "staying consistent with the old behavior while merging two visibility knobs into a single one".

  3. timhoffm commented on Jan 13, 2020

    @timhoffm
    Member

    Should we add an include_hidden parameter to control the behavior?

  4. anntzer commented on Jan 13, 2020

    @anntzer
    Contributor

    If we are going to change this (unclear whether we do) I would rather always return all of them and let the user filter them as needed -- we don't hide non-visible() children in other cases.

  5. TheAngulion commented on Jan 13, 2020

    @TheAngulion
    Author

    Thank you for the prompt and vigorous discussion on the issue. I will leave the technicalities to you as the experts but I personally side with anntzer's suggestion to always (or, at least by default) return all tick labels regardless of visibility and let the user filter. For what's it worth, I would find this the most intuitive.

  6. modified the milestones: v3.3.0, v3.4.0 on May 23, 2020
  7. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  8. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  9. modified the milestones: v3.6.0, v3.6.1 on Sep 14, 2022
  10. modified the milestones: v3.6.1, v3.6.2 on Oct 6, 2022
  11. modified the milestones: v3.6.2, v3.6.3 on Oct 27, 2022
  12. modified the milestones: v3.6.3, v3.7.0 on Jan 11, 2023
  13. github-actions commented on Apr 6, 2026

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  14. timhoffm commented on Apr 15, 2026

    @timhoffm
    Member

    Single ticks should be considered ephemal. I don't think we can or should guarantee their lifetime. Overall, the strategy should be to migrate away from single tick objects.

    I propose to close this as "won't fix".

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

    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Documentation

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions