主にmatplotlibを使用して、かなり多くのポイント(10k-100k程度)の散布図を作成するインタラクティブなプログラムを作成しようとしています。現在は機能していますが、変更のレンダリングに時間がかかりすぎます。点数が少ないのはいいのですが、点数が上がると急にイライラしてきます。だから、私はスキャッターをスピードアップする方法に取り組んでいますが、あまり運がありません
明らかな方法があります(現在実装されている方法)(更新せずにプロットが再描画されることに気付きました。ランダムへの大きな呼び出しでfpsの結果を変更したくありませんでした)。
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import time
X = np.random.randn(10000) #x pos
Y = np.random.randn(10000) #y pos
C = np.random.random(10000) #will be color
S = (1+np.random.randn(10000)**2)*3 #size
#build the colors from a color map
colors = mpl.cm.jet(C)
#there are easier ways to do static alpha, but this allows
#per point alpha later on.
colors[:,3] = 0.1
fig, ax = plt.subplots()
fig.show()
background = fig.canvas.copy_from_bbox(ax.bbox)
#this makes the base collection
coll = ax.scatter(X,Y,facecolor=colors, s=S, edgecolor='None',marker='D')
fig.canvas.draw()
sTime = time.time()
for i in range(10):
print i
#don't change anything, but redraw the plot
ax.cla()
coll = ax.scatter(X,Y,facecolor=colors, s=S, edgecolor='None',marker='D')
fig.canvas.draw()
print '%2.1f FPS'%( (time.time()-sTime)/10 )
これにより、0.7 fps が高速になります
または、スキャッターによって返されたコレクションを編集することもできます。そのために、色と位置を変更できますが、各ポイントのサイズを変更する方法がわかりません。それは私がこのように見えると思います
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import time
X = np.random.randn(10000) #x pos
Y = np.random.randn(10000) #y pos
C = np.random.random(10000) #will be color
S = (1+np.random.randn(10000)**2)*3 #size
#build the colors from a color map
colors = mpl.cm.jet(C)
#there are easier ways to do static alpha, but this allows
#per point alpha later on.
colors[:,3] = 0.1
fig, ax = plt.subplots()
fig.show()
background = fig.canvas.copy_from_bbox(ax.bbox)
#this makes the base collection
coll = ax.scatter(X,Y,facecolor=colors, s=S, edgecolor='None', marker='D')
fig.canvas.draw()
sTime = time.time()
for i in range(10):
print i
#don't change anything, but redraw the plot
coll.set_facecolors(colors)
coll.set_offsets( np.array([X,Y]).T )
#for starters lets not change anything!
fig.canvas.restore_region(background)
ax.draw_artist(coll)
fig.canvas.blit(ax.bbox)
print '%2.1f FPS'%( (time.time()-sTime)/10 )
これにより、0.7 fps が遅くなります。CircleCollection または RegularPolygonCollection を使用してみました。これにより、サイズを簡単に変更でき、マーカーの変更は気にしません。しかし、どちらも描くことができないので、どちらが速いかわかりません。ということで、現在アイデア募集中です。