May-16-2022, 09:22 PM
I never use colormesh, so I'm not familiar with it. I did find something about animating a colormesh.
https://www.tutorialspoint.com/how-to-an...matplotlib
My guess for scaling a colormesh is you do it much the same way. You keep the QuadMesh object returned by the pcolormesh() call. When you rescale the data you update the coordinates using set_array() and then call canvas.draw() and canvas.flush_events().
From you existing code you'll need to make some of the plotting variables attributes of your class.
https://www.tutorialspoint.com/how-to-an...matplotlib
My guess for scaling a colormesh is you do it much the same way. You keep the QuadMesh object returned by the pcolormesh() call. When you rescale the data you update the coordinates using set_array() and then call canvas.draw() and canvas.flush_events().
From you existing code you'll need to make some of the plotting variables attributes of your class.
c = ax.pcolormesh(x, y, layer, cmap=newcmp, edgecolor='lightgrey', linewidth=0.003) # Keep this around and give it a better nameThe method for rescaling the data will look something like this:
def update(self): # Compute new data var = self.data.layer.get() 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.c.set_array(x, y) # Reusing the QuadMesh object from the original plot. Loading in new data self.canvas.draw() # Redraw with new data self.canvas.flush_events() # Not sure if this is needed