本帖最后由 flyps 于 2020-7-16 09:24 编辑 import math
import numpy as np
#-------------------------------------------------------------------------------------------
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.pylab import mpl
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,NavigationToolbar2Tk #NavigationToolbar2TkAgg
#------------------------------------------------------------------------------------------
import tkinter as tk
root = tk.Tk()
root.geometry('1200x600')
left_frame = tk.LabelFrame(root,height=600,width=600)
left_frame.grid(row=0,column=0,padx=0,pady=0,sticky=tk.W)
left_frame.grid_propagate(0)
right_frame = tk.LabelFrame(root,height=600,width=600)
right_frame.grid(row=0,column=1,padx=0,pady=0,sticky=tk.E)
right_frame.grid_propagate(0)
tk.Label(left_frame,text='测试').grid()
f=plt.figure(num=3,figsize=(6,6))
x = np.linspace(-3,3,50)
y1 = 2*x+1
y2 = x**2
l1, = plt.plot(x,y2,label='up')
l2, = plt.plot(x,y1,color='red',linewidth=1.0,linestyle='--',label='down')
#plt.legend(handles=[l1,l2],labels=['aaa','bbb'],loc='best')
canvas=FigureCanvasTkAgg(f,right_frame)
canvas.draw() #以前的版本使用show()方法,matplotlib 2.2之后不再推荐show()用draw代替,但是用show不会报错,会显示警告self.canvas.get_tk_widget().grid(row=0,column=0,columnspan=2,sticky=tk.EWSN)
canvas.get_tk_widget().grid(row=0,column=0,sticky=tk.E)
tk.mainloop()
我需要红色部分填满right_frame,红色周边白色的不要显示,谢谢
加多下面的代码就解决了
plt.subplots_adjust(left=0.03, right=1, top=1, bottom=0.1)
有点没看懂你说的,你是想背景为红色是嘛,除了图片内?
|