相关疑难解决方法(0)

Python Tkinter在GUI中嵌入Matplotlib

我正在尝试在用Python编码的Tkinter GUI中嵌入一个绘图.我相信下面的代码只是简单地将图形放入画布中,但我没有对GUI网格中的画布位置进行任何控制.我希望能够将我的GUI的子部分作为情节...而不是整个部分.如何定位此画布小部件?

#!/usr/apps/Python/bin/python
import matplotlib, sys
matplotlib.use('TkAgg')
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from Tkinter import *

master = Tk()
master.title("Hello World!")
#-------------------------------------------------------------------------------

f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a.plot(t,s)


dataPlot = FigureCanvasTkAgg(f, master=master)
dataPlot.show()
dataPlot.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
#-------------------------------------------------------------------------------
master.mainloop()
Run Code Online (Sandbox Code Playgroud)

python grid canvas tkinter matplotlib

19
推荐指数
1
解决办法
3万
查看次数

Matplotlib 窗口大小、标题等

我是 python 和 matplotlib 的新手。我有一个项目,我需要使用 matplotlib 在 Tkinter GUI 中创建一个图形。我发现并使用了这个代码:

import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = (20, 35, 30, 35, 27)
menStd =   (2, 3, 4, 1, 2)

ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)

womenMeans = (25, 32, 34, 20, 25)
womenStd =   (3, 5, 2, 3, 3)
rects2 …
Run Code Online (Sandbox Code Playgroud)

python matplotlib figure

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

matplotlib ×2

python ×2

canvas ×1

figure ×1

grid ×1

tkinter ×1