FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Drawing the canvas does not populate ticklabels on MacOSX backend · Issue #19268 · matplotlib/matplotlib · GitHub

Repository navigation

Drawing the canvas does not populate ticklabels on MacOSX backend #19268

Closed

Description

Bug report

Bug summary

This is basically the same issue as #6103, but I have found that the "correct" approach selectively fails on the macosx backend. I decided to open a separate issue because there's a lot going on in the original thread.

(BTW I do support the suggestion in the original thread that get_{x/y}ticklabels should implicitly draw so that it always returns a sensible result).

Code for reproduction

import matplotlib.pyplot as plt
ax = plt.figure().subplots()
ax.plot(["a", "b", "c"], [1, 2, 3])
ax.figure.canvas.draw()
print(ax.get_xticklabels())

Actual outcome

Using the MacOSX backend:

[Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, '')]

Expected outcome

Using an agg-based backend:

[Text(0, 0, 'a'), Text(1, 0, 'b'), Text(2, 0, 'c')]

Matplotlib version

  • Operating system:
  • Matplotlib version: (import matplotlib; print(matplotlib.__version__)) 3.3.3
  • Matplotlib backend (print(matplotlib.get_backend())): macosx
  • Python version: 3.8
  • Jupyter version (if applicable): n/a
  • Other libraries: n/a

Activity

  1. mwaskom commented on Jan 9, 2021

    Author

    It occurs to me that this is maybe the same issue as #19197.

    Indeed, s/ax.figure.canvas.draw()/ax.figure.draw(ax.figure.canvas.get_renderer())/ does produce the expected output, BUT, s/ax.figure.canvas.draw()/plt.draw() does not.

  2. greglucas commented on Jan 10, 2022

    Contributor

    The original issue was resolved by #21758

    However, the plt.draw() from #19268 (comment) doesn't work with any interactive backends because it is using a draw_idle call: ax.figure.canvas.draw_idle(), and the event loop doesn't run to trigger a draw. I think we can close this as the macosx backend is consistent with the other backends and changing plt.draw() would be a separate issue.

  3. jklymak commented on Jan 10, 2022

    Member

    I think in current matplotlib we are suggesting fig.draw_without_rendering() as an easy user-accessible way of calling a draw. Though I agree that if the users is calling for the ticks, we should do a draw to give them the ticks.

  4. greglucas commented on Mar 5, 2022

    Contributor

    Closing as the original example is now fixed on main.

    import matplotlib.pyplot as plt
    ax = plt.figure().subplots()
    ax.plot(["a", "b", "c"], [1, 2, 3])
    ax.figure.canvas.draw()
    print(ax.get_xticklabels())

    produces:

    [Text(0, 0, 'a'), Text(1, 0, 'b'), Text(2, 0, 'c')]
  5. added this to the v3.6.0 milestone on Mar 7, 2022
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


      Back | FazBrowse Home | New Git URL