5

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)?

before expanding the window after expanding the window

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)
3
  • If you are doing the embedding correctly, it should behave like any other widget and this is a Tk issue, not an mpl issue. Commented Sep 7, 2013 at 18:08
  • can you please explain? I added above the embedding code Commented Sep 8, 2013 at 8:52
  • matplotlib.org/examples/user_interfaces <- see examples here Commented Sep 8, 2013 at 15:23

1 Answer 1

2

This is most likely related to this question. The gist is that there are two parts to making a Tk grid cell grow:

  • Use the 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.
  • Tell the parent/master to make the respective column/row grow when resizing by calling 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.