matplotlib
import matplotlib as mpl
mpl.use('TkAgg')
import tkinter as tk
from matplotlib import figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
root = tk.Tk()
def show_plot():
fig = figure.Figure()
ax=fig.add_subplot()
ax.scatter([1, 2, 3, 4], [4, 7, 2, 4])
canv = FigureCanvasTkAgg(fig, canvas)
canv.draw()
canv.get_tk_widget().pack(fill=tk.BOTH, expand=1)
canvas = tk.Canvas(root, width=600, height=600)
canvas.pack(fill=tk.NONE, expand=0)
tk.Button(root, text='show plot', command=show_plot).pack()
root.mainloop()
和fill
参数,但这不起作用。
事实证明这很简单:我只需要指定matplotlib的大小:
expand
有关如何与Matplotlib中的精确像素一起工作的更多信息