以下代码在默认位置绘制直方图,例如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()