我正在尝试在tkinter
canvas
中绘制数据框。当我将kind
用作 bar 时,该图看起来不错。但是当我将其更改为 line 时,xticks并不完全可见。
我希望下面的屏幕截图会有所帮助。
这是我使用的代码:
self.fig = Figure(figsize=(8, 4.6), dpi=100)
self.fig.subplots_adjust(top=0.93, bottom=0.19, right=0.97, left=0.17)
#self.fig.autofmt_xdate(rotation=30)
self.canvas = FigureCanvasTkAgg(self.fig, self)
self.canvas.get_tk_widget().place(x=400,y=240)
self.canvas.get_tk_widget().config(relief=tk.RAISED)
self.toolbar_frame = tk.Frame(master=self, height=20)
self.toolbar_frame.place(x=700,y=700)
self.toolbar = NavigationToolbar2Tk(self.canvas, self.toolbar_frame)
self.toolbar.update()
for button in self.toolbar.winfo_children():
button.config(background='#464646')
self.ax = self.fig.add_subplot(111)
self.df.plot(x=self.labels[buttonID].cget('text'), ax=self.ax, kind="line")
self.ax.set_xticks(range(len(self.labels[buttonID].cget('text'))))
plt.setp(self.ax.get_xticklabels(), visible=True, rotation=30, ha='right')
self.canvas.draw()
答案 0 :(得分:0)
Instead of default pandas plot
self.df.plot(x=self.labels[buttonID].cget('text'), ax=self.ax, kind="line")
self.ax.set_xticks(range(len(self.labels[buttonID].cget('text'))))
Use Matplotlib Pyplot:
self.ax.plot(self.df[self.labels[self.buttonIDcopy].cget('text')], self.df['Value'])