RuntimeError: CGContextRef is NULL

I'm trying to have animated plots using draw_artist on mac os x and I got an error with the following script:

import numpy as np
import matplotlib.pyplot as plt

plt.ion()
plt.figure()
subplot = plt.subplot(1,1,1)
axis = plt.imshow(np.random.random((10,10)))
plt.draw()
subplot.draw_artist(axis)
plt.show()

The traceback is:

Traceback (most recent call last):
  File "matplotlib-bug.py", line 8, in <module>
    subplot.draw_artist(axis)
  File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/axes.py", line 1946, in draw_artist
    a.draw(self._cachedRenderer)
  File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/image.py", line 338, in draw
    gc = renderer.new_gc()
  File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 105, in new_gc
    self.gc.save()
RuntimeError: CGContextRef is NULL

Is there something wrong in my script (it seems to be working on linux) ?

Information:
matplotlib version: 1.0.0
python version 2.7
macosx version: 10.6.4

Nicolas

2010/10/4 Nicolas Rougier <Nicolas.Rougier@...2073...>:

I'm trying to have animated plots using draw_artist on mac os x and I got an error with the following script:

import numpy as np
import matplotlib.pyplot as plt

plt.ion()
plt.figure()
subplot = plt.subplot(1,1,1)
axis = plt.imshow(np.random.random((10,10)))
plt.draw()
subplot.draw_artist(axis)
plt.show()

The traceback is:

Traceback (most recent call last):
File "matplotlib-bug.py", line 8, in <module>
subplot.draw_artist(axis)
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/axes.py", line 1946, in draw_artist
a.draw(self._cachedRenderer)
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/image.py", line 338, in draw
gc = renderer.new_gc()
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 105, in new_gc
self.gc.save()
RuntimeError: CGContextRef is NULL

Is there something wrong in my script (it seems to be working on linux) ?

I don't know what it is, and it looks like some problem with the
Mac-native backend, but I believe you can sort it out by just
switching the backend to e.g. TkAgg.

Friedrich