我已经搜索过相关内容,例如Python Tkinter 在 GUI 中嵌入 Matplotlib,但是仍然无法理解。基本上,我正在尝试在由 tkinter 制作的球员窗口内绘制篮球比赛中球员能力的花式图表。
self.fig = Figure(figsize=(1.5,1.5))
self.ax = self.fig.add_axes([0.025,0.025,0.95,0.95],polar=True)
self.plot_widget = FigureCanvasTkAgg(self.fig, master=self.top)
self.ax.grid(False)
N = 5
theta = np.arange(0.0, 2*np.pi, 2*np.pi/N)
radii = [self.thisPlayer.rebounds,self.thisPlayer.freeThrows,self.thisPlayer.steal,self.thisPlayer.underRim,self.thisPlayer.distance]
width = [2*np.pi/(N),2*np.pi/(N),2*np.pi/(N),2*np.pi/(N),2*np.pi/(N)]
bars = pl.bar(0 , 20,width=2*np.pi, linewidth = 0) + pl.bar(theta, radii, width=width, bottom=0.2)
for r,bar in zip(radii, bars):
bar.set_facecolor( cm.jet(r/20.))
bar.set_alpha(0.5)
self.ax.set_xticklabels([])
self.ax.set_yticklabels([])
self.plot_widget.show()
self.plot_widget.get_tk_widget().pack()
发生的情况是,播放器窗口现在有了绘图小部件,但是绘图没有显示出来。另一方面,仅绘制未嵌入tkinter中的能力运行良好。对于我的英语问题,我感到抱歉。
谢谢您的帮助。