Save multiple supblots at once using tkinter/FigureCanvasTkAgg

855 views Asked by At

I am trying to develop a GUI which allows me to plot data from subfiles and show it directly in the GUI and save all plotted files in one file. Showing the plots works fine, but when I try to save the whole figure, only the last plotted subfigure is saved.

Here's the important part of the code:

def callback(self):
    name= fd.askopenfilename()
    (y,z) = np.loadtxt(name, usecols=(0,1), unpack = True)
    global counter
    global f
    f = Figure(figsize=(2,2), dpi=100)
    str1 = "111"
    str1 = str(int(str1))
    print(str(str1))
    a = f.add_subplot(int(str1))
    a.plot(y,z)
    global canvas
    canvas = FigureCanvasTkAgg(f, master=root)
    canvas.show()
    canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand = 1 )
 def savecanvas(self):
    f.savefig("canvas2.png")    

Each function is connected to a button as a command. Nevermind the "str1"-construction. It's just there in case I want to change the size of the following subplots.

0

There are 0 answers