问题描述 投票:0回答:0

matplotlib

我已经尝试更改plot和画布的要求中的
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

将产生一个600 x 800像素的图。用父帆布的宽度和高度(每个除以DPI)替换6和8。
有关如何与Matplotlib中的精确像素一起工作的更多信息
    

python matplotlib tkinter
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.