Python Forum
How to instantly update the plot by getting values from a Scale widget?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to instantly update the plot by getting values from a Scale widget?
#16
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.
c = ax.pcolormesh(x, y, layer, cmap=newcmp, edgecolor='lightgrey', linewidth=0.003)  # Keep this around and give it a better name
The 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
Reply


Messages In This Thread
RE: How to instantly update the plot by getting values from a Scale widget? - by deanhystad - May-16-2022, 09:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Update exist plot while change upper limit or lower limit SamLiu 1 1,031 Feb-05-2023, 10:09 AM
Last Post: SamLiu
Exclamation Update Point Coordinates from Mouse Event in a Plot Jguillerm 2 1,371 Jan-10-2023, 07:53 AM
Last Post: Jguillerm
  [Tkinter] Update matplotlib plot correctly Particledust 0 4,704 Apr-20-2020, 04:59 PM
Last Post: Particledust
  [Tkinter] Scale at the Top Friend 5 2,934 Jul-20-2019, 05:02 PM
Last Post: Yoriz
  Update plot by <Return> bind with entry widget Zorro 1 4,224 Mar-09-2019, 12:27 PM
Last Post: Zorro
  [Tkinter] update the content of Text widget atlass218 10 16,412 Dec-15-2018, 11:51 AM
Last Post: atlass218
  [Tkinter] Update value in Entry widget dannyH 7 27,931 Apr-02-2017, 10:12 AM
Last Post: dannyH
  [Tkinter] Resetting scale value back to 0 after the slider loses focus lwhistler 3 7,114 Mar-07-2017, 10:01 PM
Last Post: Larz60+
  Bokeh - dynamic update widget.Select values sixteenornumber 0 10,347 Dec-28-2016, 02:15 PM
Last Post: sixteenornumber

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020