[Matplotlib-devel] Confusion about draw_artist

Thomas Caswell tcaswell at gmail.com
Wed Jan 4 21:58:45 EST 2017


Unless you have flagged the artist as `animated` (via `set_animated` or by
kwarg), it will be drawn as part of the next re-draw.  You are better off
just changing the `fig.canvas.draw()` to `fig.canvas.draw_idle()` and
letting the GUI decide when to re-draw things.

If you want to get any performance gain from animated artists + draw_artist
you will need to use blitting (which will work with the OSX backend in 2.0).

Tom

On Wed, Nov 30, 2016 at 2:11 PM Matthew Brett <matthew.brett at gmail.com>
wrote:

> Hi,
>
> We're using 'draw_artist' in an image viewer, and I just found that
> our viewer is crashing using the macosx backend.  Here's a minimal
> example:
>
> 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)
>
> This generates:
>
> 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
>
> for the macosx backend, and works correctly for the tkagg backend.
>
> I can't see any way to cache the renderer here - could someone give me
> a pointer?
>
> Cheers,
>
> Matthew
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20170105/c1202187/attachment.html>


More information about the Matplotlib-devel mailing list