在tkinter的所需位置绘制直方图

时间:2019-02-09 08:48:06

标签: python pandas matplotlib tkinter

以下代码在默认位置绘制直方图,例如tkinter的左侧,右侧或中心。如何在所需的屏幕位置显示图形。非常感谢。

import tkinter as tk
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

dataSet=pd.read_excel('graph.xlsx')
df=pd.DataFrame(dataSet)

L1Values=df.iloc[:,1]
L2Values=df.iloc[:,2]

# tkinter GUI
predict=tk.Tk()
canvas1 = tk.Canvas(predict, width = 800, height = 600)
canvas1.pack()

figure1 = plt.Figure(figsize=(5,4), dpi=50)
ax1 = figure1.add_subplot(111)
ax1.hist(L1Values, 30)
hist1 = FigureCanvasTkAgg(figure1, predict) 
hist1.get_tk_widget().pack(side=tk.RIGHT, fill=tk.BOTH)
ax1.legend() 
ax1.set_xlabel('Layer1 Temperature')
ax1.set_title('Layer1 Temperature Vs. Soil Temperature')

predict.mainloop()

0 个答案:

没有答案