This is a follow up question to the one asked before. I have a code below:
from tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
class PlotClass():
def __init__(self):
fig = Figure(figsize=(5,5),dpi=70,facecolor='cyan')
ax = fig.subplots()
ax.set_title("Ttile")
ax.set_ylabel("y")
ax.set_xlabel("x")
ax.set_xlim(100,9000)
ax.set_ylim(130,-10)
ax.set_facecolor("cyan")
x = [125,250,500,1000,2000,4000,8000]
ticks = [125,250,500,"1K","2K","4K","8K"]
xm = [750,1500,3000,6000]
ax.set_xscale('log', basex=2)
ax.set_xticks(x)
ax.set_xticks(xm, minor=True)
ax.set_xticklabels(ticks)
ax.set_xticklabels([""]*len(xm), minor=True)
ax.yaxis.set_ticks([120,110,100,90,80,70,60,50,40,30,20,10,0,-10])
self.line, = ax.plot([],[],'r+',markersize=15.0,mew=2)
self.line2,= ax.plot([],[],'-o',markersize=15.0,mew=2)
ax.grid(color="grey")
ax.grid(axis="x", which='minor',color="grey", linestyle="--")
self.canvas = canvas = FigureCanvasTkAgg(fig, master=master)
canvas.show()
canvas.get_tk_widget().grid(column=0,row=2,columnspan=3,rowspan=15)
self.spin = Spinbox(master, from_=125,to=8000,command=self.action)
self.spin.grid(column=5,row=2)
self.spin2 = Spinbox(master, from_=-10,to=125,command=self.action)
self.spin2.grid(column=5,row=3)
self.button = Button(master, text="plot here",command=self.plot)
self.button.grid(column=5,row=4)
def ok(self, x=1000,y=20):
self.line.set_data([x],[y])
self.canvas.draw_idle()
def action(self):
self.ok(float(self.spin.get()),float(self.spin2.get()))
def linecreate(self, x=1000,y=20):
self.line2.set_data([x],[y])
self.canvas.draw_idle()
def plot(self):
self.linecreate(float(self.spin.get()),float(self.spin2.get()))
master = Tk()
plotter = PlotClass()
plotter.ok(125,10)
master.mainloop()
It plots graph by feeding the x and y axis with values from two tkinter spinbox, as the value in spinbox changes the plot redraws and changes the markers location based on the values provided by the spinboxes. Now, I have added a tkinter button and linked it to a function that would draw another plot using the same values coming from the spinboxes but now I could not understand how to draw the new plot without removing the previous plots when the button is pressed. What I mean is, plotting on new locations (adding more markers) on the graph without removing the previous plot locations (previous markers) that has been added by the button press. Like when button clicks it keeps adding the new markers based on the spinbox values without removing the previous ones. In the previous question it was removing the existing plots and adding new ones every time the spinbox value changes but now I could not understand how to plot on new location without removing the previous plot.