Jan-06-2022, 10:33 PM
(This post was last modified: Jan-06-2022, 10:54 PM by Larz60+.
Edit Reason: fixed incorrect bbcode tags
)
I have a frame within my root window and wish to place a plot inside the frame. What I have so far is the following:
The problem I have is that I want to increase the plot size so it occupies the entire frame. I'm unsure why adjusting plt.rcParams doesn't do what I need.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from tkinter import Tk,Frame,TOP,BOTH from matplotlib import pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import numpy as np plt.rcParams[ "figure.figsize" ] = [ 18 , 10 ] root = Tk() root.wm_title( "Root Window" ) root.geometry( '1500x1000' ) x = np.linspace( 0 , 2 * np.pi, 400 ) y = np.sin(x * * 2 ) fig, ax = plt.subplots() ax.plot(x, y) canvas_frame = Frame(root,bg = 'yellow' ) canvas_frame.pack(side = TOP,expand = True ) canvas = FigureCanvasTkAgg(fig, master = canvas_frame) canvas.get_tk_widget().pack(side = TOP,fill = BOTH,expand = True ) canvas.draw() root.mainloop() |