I rewrote them in this way. did you mean it in this way? this time the code doesnt remove the old figures. I didn't understand what is the usage of set_array(x,y)
def plot(self, var, window): global ax, newcmp, nx, ny, x, y, num_reshaped nx = 3 ny = 4 num_reshaped = np.array(self.num).reshape(10, nx * ny) layer = num_reshaped[var - 1:var, :] layer = layer.reshape(nx, ny) x, y = np.mgrid[slice(0, nx + 1, 1), slice(0, ny + 1, 1)] self.figure = Figure(figsize=(4, 4)) ax = self.figure.add_subplot(111) col_type = cm.get_cmap('rainbow', 256) newcolors = col_type(np.linspace(0, 1, 1000)) white = np.array([1, 1, 1, 1]) newcolors[:1, :] = white newcmp = ListedColormap(newcolors) c = ax.pcolormesh(x, y, layer, cmap=newcmp, edgecolor='lightgrey', linewidth=0.003) ax.figure.colorbar(c) self.canvas = FigureCanvasTkAgg(self.figure, window) self.canvas.draw() self.canvas.get_tk_widget().pack() def open(self): self.toplevel = tk.Toplevel() self.toplevel.geometry('+500+100') self.plot(self.data.layer.get(), self.toplevel) def update(self, *args): var = self.data.layer.get() layer = num_reshaped[var - 1:var, :] layer = layer.reshape(nx, ny) c = ax.pcolormesh(x, y, layer, cmap=newcmp, edgecolor='lightgrey', linewidth=0.003) ax.figure.colorbar(c) #c.set_array(x, y) self.canvas.draw() # Redraw with new data #self.canvas.flush_events()