python - 如何在 tkinter 的同一张图上绘制多条线?
问题描述
我是 tkinter 的新手,我需要能够在同一个图表上绘制多个线图,每个线图都有自己的图例。我可以使用 show () 在 matplotlib 中执行此操作,但随后图形与 GUI 窗口分离。我的代码从我创建的文件列表中获取文件,然后将它们绘制在屏幕上,但不断覆盖每个图表 - 有没有办法做到这一点,以便所有折线图出现在 tkinter 的同一个图表上?
for item in myfile_list:
x, y = np.loadtxt(item + '_' + 'Test.csv', skiprows=1, usecols=[x_axis_column, y_axis_column],
unpack=True, delimiter=',')
# graph size in inches
fig = Figure(figsize=(5, 5))
a = fig.add_subplot(111)
a.plot(x, y, color='blue')
a.set_title("Title", fontsize=16)
a.set_ylabel("Y", fontsize=14)
a.set_xlabel("X", fontsize=14)
canvas = FigureCanvasTkAgg(fig, master=chart_frame)
# place graph in first row and column of chart_frame
canvas.get_tk_widget().grid(row=0, column=0)
canvas.draw()
toolbar_frame = Frame(plot_frame)
toolbar_frame.grid(row=1, column=0)
toolbar = NavigationToolbar2Tk(canvas, toolbar_frame)
toolbar.update()
解决方案
推荐阅读
- javascript - 使用自定义属性变量时 CSS 属性不会改变
- r - 从 R 导入股息时出现错误
- jquery - 如果它在数组中,则jQuery Datepicker将类添加到日期
- javascript - 如何在 npm install 中克服这个错误?
- python - 如何在多个打印命令之间随机选择?
- python - 重做在 Windows 上无法为 Tkinter 文本小部件工作
- ruby - 为什么你可以在函数中使用另一种方法而不是赋值运算符来更改 Ruby 中局部变量的值?
- python - 如何读取 brat annotation toll 提供的 ann 文件并将它们转换为 python 中的数据框?
- python - 是否可以在 Python Wand(绘图标题)中使用多种字体?
- python - 将信号转发给使用 Popen 创建的子进程