Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

633
Visualizações
Problem resizing plot on tkinter figure canvas

Python 3.9 on Mac running OS 11.6.1. My application involves placing a plot on a frame inside my root window, and I'm struggling to get the plot to take up a larger portion of the window. I thought rcParams in matplotlib.pyplot would take care of this, but I must be overlooking something.

Here's what I have so far:

import numpy as np
from tkinter import Tk,Frame,TOP,BOTH

import matplotlib
from matplotlib import pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

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) # also tried adjusting size of frame but that didn't help
canvas_frame.pack(side=TOP,expand=True)
canvas = FigureCanvasTkAgg(fig, master=canvas_frame)
canvas.draw()
canvas.get_tk_widget().pack(side=TOP,fill=BOTH,expand=True)


root.mainloop()

For my actual application, I need for canvas to have a frame as its parent and not simply root, which is why canvas_frame is introduced above.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

try something like this:

fig.subplots_adjust(left=0.05, bottom=0.07, right=0.95, top=0.95, wspace=0, hspace=0)

this is output, figure now takes more screen area % [figure now takes more screen realestate1

over 4 years ago · Santiago Trujillo Relatório

0

I addition to the suggestion of changing the margins, you could also add fill=BOTH to the canvas widget.

canvas_frame.pack(side=TOP,expand=True,fill=BOTH)

This makes the figure canvas take up more space, but the plot doesn't take the whole window. However, if I resize the window, then the plot takes the whole window.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda