1
ユーザーが画面をクリックするたびに1つのプロットを再描画しようとしています。 現在、プロットは最初のクリック時に描画されます。その後、新しいプロットがキャンバスに追加されます。私がしたいのは、最初のプロットを「削除」または「クリア」してそれを再描画するか、新しいデータで更新することです。Tkinter Matplotlibの更新
これは、この特定のプロットの描画を担当する部分である:
class AppGUI(Tk.Frame):
def __init__(self, parent):
self.parent = parent
self.initGUI()
self.plot()
def initGUI(self):
self.vf_frame = Tk.Frame(self.parent, bd=1, relief=Tk.SUNKEN)
self.vf_frame.pack(side=Tk.TOP, fill="both", expand=True)
def plotVF(self, u, v):
# Canvas of VF
m = np.sqrt(np.power(u, 2) + np.power(v, 2))
xrange = np.linspace(0, u.shape[1], u.shape[1]);
yrange = np.linspace(0, u.shape[0], u.shape[0]);
x, y = np.meshgrid(xrange, yrange)
mag = np.hypot(u, v)
scale = 1
lw = scale * mag/mag.max()
f, ax = plt.subplots()
h = ax.streamplot(x, y, u, v, color=mag, linewidth=lw, density=3, arrowsize=1, norm=plt.Normalize(0, 70))
ax.set_xlim(0, u.shape[1])
ax.set_ylim(0, u.shape[0])
ax.set_xticks([])
ax.set_yticks([])
#cbar = f.colorbar(h, cax=ax)
#cbar.ax.tick_params(labelsize=5)
c = FigureCanvasTkAgg(f, master=self.vf_frame)
c.show()
c.get_tk_widget().pack(side=Tk.LEFT, fill="both", expand=True)
私はこの結果を達成するために私のクラスのf
とax
属性を行う必要がありますか?明確にするため、plotVF
は他の方法で更新されています。
PS:色付きのバーにコメント行を表示することもできません。それは'Streamplot' object has no attribute 'autoscale_None'
と言います。