0

From a more complex example, i distilled this minimal example:

from tkinter import Frame, Tk

class Example(Frame):

    def __init__(self, master):
        super().__init__(master)
        plt.figure() # this makes the window smaller


def main():
    root = Tk()
    root.geometry("500x500")
    app = Example(root)
    root.mainloop()


if __name__ == '__main__':
    main()

The plt.figure() makes the window smaller and the process not end when I click the X on the top right. I really don't understand how a matplotlib command could cause this behaviour. A plt.close() allows me to kill the process by closing the window, but doesn't solve the size problem, and starts up the window behind other open windows.

rikyeah
  • 1,896
  • 4
  • 11
  • 21
  • To make the axes fill the figure (no padding), you need to set the axes position: `ax.set_position([0, 0, 1, 1])`. Don’t use subplotpars at all. Once you have the figure looking how you want, then work on the embedding. – Jody Klymak May 18 '22 at 13:46
  • https://stackoverflow.com/questions/24535393/matplotlib-getting-subplots-to-fill-figure – Jody Klymak May 18 '22 at 13:46
  • Thanks, but this doesn't solve my problem with the GUI – rikyeah May 18 '22 at 14:23
  • Well you are asking too many questions at once. – Jody Klymak May 18 '22 at 14:25
  • My question is just one: my gui shrinks in size when I use the generate_voronoi function instead of the dummy np.random, despite both returning numpy arrays, why is that? – rikyeah May 18 '22 at 14:39

1 Answers1

0

Solved it by using plt.Figure() instead. Also plt.savefig() poses this problem, so if anyone reading this has this same issue, you can try:

fig = plt.Figure()
# work on figure...
fig.savefig("file.png")
rikyeah
  • 1,896
  • 4
  • 11
  • 21