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

Draw not caching with macosx backend · Issue #7550 · matplotlib/matplotlib · GitHub

Repository navigation

Draw not caching with macosx backend #7550

Closed

Description

Using local install of current git master - the following code works with the tkagg backend, but raises an error with the macosx backend:

import matplotlib
matplotlib.use('macosx')
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)
im = plt.imshow([[1, 2], [3, 4]])
fig.canvas.draw()
ax.draw_artist(im)

Error for macosx backend is:

Traceback (most recent call last):
  File "draw_artist.py", line 8, in <module>
    ax.draw_artist(im)
  File "/Users/mb312/dev_trees/matplotlib/lib/matplotlib/axes/_base.py",
line 2423, in draw_artist
    raise AttributeError(msg)
AttributeError: draw_artist can only be used after an initial draw
which caches the render

It seems to me that the previous call fig.canvas.draw() is the "initial draw" that should cache the renderer. So, is this a bug?

Activity

  1. modified the milestones: , on Dec 2, 2016
  2. tacaswell commented on Dec 2, 2016

    Member

    For osx, draw does not actually run the renderer, it tells the GUI manager that the window is invalid and to please re-draw it at it's earliest convenience. The actual rendering happens in a callback from the GUI thread.

    Once the figure is displayed on the screen once, it will work.

  3. matthew-brett commented on Dec 2, 2016

    ContributorAuthor

    Sorry to expose my ignorance, but how can I make sure that the figure is displayed on the screen? plt.show() before draw_artist in the above script does not work, for example. Is there any way of forcing the code to build a renderer?

  4. tacaswell commented on Dec 2, 2016

    Member

    What is the use case driving this question?

  5. matthew-brett commented on Dec 3, 2016

    ContributorAuthor

    It's the image viewer we have here. Basically it shows several panels showing different slices from a 3D image, with crosshairs on top of the image. When the user clicks the crosshairs, it changes the position of the crosshairs, and the slices displayed. We use draw_artist to change the slices and crosshairs. When we initialize the viewer, and thence call the slice / crosshair display function here - the viewer crashes with the message above.

  6. modified the milestones: , on May 3, 2017
  7. modified the milestones: , on Oct 9, 2017
  8. dopplershift commented on Oct 24, 2017

    Contributor

    I wonder if #9495 helps at all with this. With the simple script above it still crashes, but I wonder if flushing the events helps in more of a real-world case. I'm also able to get the above script to work just fine with a plt.pause(0.0001)--I don't know if that's of any help to you guys, though.

  9. modified the milestones: needs sorting, v3.5.1 on Nov 30, 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


      Back | FazBrowse Home | New Git URL