I am trying to build a grid of frames in each there is a matplotlib figure. When I resize the window the figure remain with fix size and are not resizing to fit the empty space. Is there a way to make the figure change its size according to the canvas (hopefully that it does change with the window size)?
This is how I do the embedding in each frame:
self._figure = pyplot.figure(figsize=(4,4))
self._axes = self._figure.add_subplot(111)
self._canvas = FigureCanvasTkAgg(self._figure, master=self._root)
self._canvas.get_tk_widget().grid(row=1,column=1,rowspan = 4)
This is most likely related to this question. The gist is that there are two parts to making a Tk grid cell grow:
sticky
keyword when applying grid
to your widget, e.g., widget.grid(..., sticky=Tkinter.NSEW
(Python 2.7) to make widget
be able to grow in all four directions. See this documentation for more details.parent.grid_columnconfigure(...)
and/or parent.grid_rowconfigure(...)
with the desired row, column, and weight
keyword. E.g., parent.grid_columnconfigure(col=0, weight=1)
makes the first column take all available space (as long as there are no other columns, or they have not been similary configured). See the grid_columnconfigure documentation and the grid_rowconfigure documentation for more details, e.g., about how the weights affect multiple columns/rows.This page contains many more details about grid layouts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With