0
私はSpeeding up Matplotlib -- Bastibeに従っていて、図で変更されたものを更新するだけでアニメーションをテストしていました。 MacPortsによってインストールされたMac OS X 10.11.4、Python 3.4を使用しています。MacOSXバックエンドでMatplotlib draw_artist(axis.patch)が失敗する
'''Import modules'''
import matplotlib.pyplot as plt
import numpy as np
import time
'''Initialize figure and axis, perform first draw on canvas'''
fig, ax = plt.subplots()
line, = ax.plot(np.random.randn(100))
plt.show(block=False)
fig.canvas.draw()
'''Count how many plots made within 1 second'''
tstart = time.time()
num_plots = 0
while time.time()-tstart < 1: # within 1 second
line.set_ydata(np.random.randn(100)) # update line
ax.draw_artist(ax.patch) # draw background
ax.draw_artist(line) # draw line
fig.canvas.update() # update canvas
fig.canvas.flush_events()
num_plots += 1 # count++
print(num_plots)
このコードは、Python 3.4 + Qt5AggバックエンドとのUbuntu 14.04上で正常に動作します:コードは次のようになります。しかし、Macでは、それは報告する
Traceback (most recent call last):
File "./test.py", line 19, in <module>
ax.draw_artist(ax.patch)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/_base.py", line 2340, in draw_artist
a.draw(self._cachedRenderer)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/patches.py", line 486, in draw
gc = renderer.new_gc()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/backends/backend_macosx.py", line 99, in new_gc
self.gc.save()
RuntimeError: CGContextRef is NULL
何か提案はありがとう!
良いアドバイスマイク。カーネルを再起動する必要があります。それ以外の場合、matplotlibはバックエンドがすでに選択されているため、 'matplotlib.use( 'Qt4Agg')'は無効です。プロット 'plt.close()'を閉じる必要があります。そうしないと、そこにハングします。 –
ありがとうございます。実際、私はQtバックエンドの動作を知っていますが、元のMacOSXバックエンドに何が間違っているかを知りたがっています。 Qtバックエンドを元のものにする代わりに、Qtバックエンドを使用する利点があるかどうか尋ねる必要がありますか? – astroboylrx