Tkinter 中的交互式图形
Interactive figures in Tkinter
我正在寻找有关在 Tkinter 中绘图的建议。我正在使用 Spyder IDE。我将 matplotlib 用于实时图表,它们工作正常。但我希望这些图是交互式的,即我应该能够放大,当指向图上的特定区域时获取 (x,y) 坐标等,这对于 matplotlib 似乎不可行。
我的问题是,在这种情况下我可以使用什么绘图库?我本来打算使用 Plotly,但我读到它与 Tkinter 不兼容。有什么东西可以帮助在 Tkinter 中制作交互式图形吗?提前谢谢你。
But I want the plots to be interactive i.e. I should be able to zoom
in, get the (x,y) coordinates when pointed over a specific region on
plot etc. which does not seem feasible with matplotlib.
使用 matplotlib 是可以的,这里有一个示例:
from tkinter import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
def plot():
fig = Figure(figsize = (5, 5), dpi = 100)
y = [i**2 for i in range(101)]
plot1 = fig.add_subplot(111)
plot1.plot(y)
canvas = FigureCanvasTkAgg(fig,master = window)
canvas.draw()
canvas.get_tk_widget().pack()
toolbar = NavigationToolbar2Tk(canvas,window)
toolbar.update()
canvas.get_tk_widget().pack()
window = Tk()
window.title('Plotting in Tkinter')
window.state('zoomed') #zooms the screen to maxm whenever executed
plot_button = Button(master = window,command = plot, height = 2, width = 10, text = "Plot")
plot_button.pack()
window.mainloop()
您可以 select 缩放按钮放大矩形区域,然后缩小,通过 select 使用移动工具在图表中移动,并将鼠标悬停在图表中的某个点上以获得它的 x-y 坐标显示在 right-bottom 角上。所有这些都在 tkinter window.
中
My question is, what plotting library can I use in such a case?
如果仅使用 matplotlib
就包含了所有 above-mentioned 交互性,那么我认为您不需要使用任何其他库。
我正在寻找有关在 Tkinter 中绘图的建议。我正在使用 Spyder IDE。我将 matplotlib 用于实时图表,它们工作正常。但我希望这些图是交互式的,即我应该能够放大,当指向图上的特定区域时获取 (x,y) 坐标等,这对于 matplotlib 似乎不可行。 我的问题是,在这种情况下我可以使用什么绘图库?我本来打算使用 Plotly,但我读到它与 Tkinter 不兼容。有什么东西可以帮助在 Tkinter 中制作交互式图形吗?提前谢谢你。
But I want the plots to be interactive i.e. I should be able to zoom in, get the (x,y) coordinates when pointed over a specific region on plot etc. which does not seem feasible with matplotlib.
使用 matplotlib 是可以的,这里有一个示例:
from tkinter import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
def plot():
fig = Figure(figsize = (5, 5), dpi = 100)
y = [i**2 for i in range(101)]
plot1 = fig.add_subplot(111)
plot1.plot(y)
canvas = FigureCanvasTkAgg(fig,master = window)
canvas.draw()
canvas.get_tk_widget().pack()
toolbar = NavigationToolbar2Tk(canvas,window)
toolbar.update()
canvas.get_tk_widget().pack()
window = Tk()
window.title('Plotting in Tkinter')
window.state('zoomed') #zooms the screen to maxm whenever executed
plot_button = Button(master = window,command = plot, height = 2, width = 10, text = "Plot")
plot_button.pack()
window.mainloop()
您可以 select 缩放按钮放大矩形区域,然后缩小,通过 select 使用移动工具在图表中移动,并将鼠标悬停在图表中的某个点上以获得它的 x-y 坐标显示在 right-bottom 角上。所有这些都在 tkinter window.
中My question is, what plotting library can I use in such a case?
如果仅使用 matplotlib
就包含了所有 above-mentioned 交互性,那么我认为您不需要使用任何其他库。