0

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.

  • `f` keeps access only to last created subfigure. You could keep all subfigures on list and get subfigures in separated files -`f[0].savefig()`, `f[1].savefig()`. But `matplotlib` may not have function to create one image from separated subfigures. – furas Jan 09 '17 at 12:38
  • maybe you should create one `Figure` and many subplots - ie. `f.add_subplot("551")`, `f.add_subplot("552")`, etc. - then it should save all subplots in one image. – furas Jan 09 '17 at 12:44

0 Answers0