Hi.
I adjust the objects in the plot dynamically, but it only applies when the frame has been resized manually by mouse dragging.
I had got a similar problem long before and Refresh(), Update(), or something was helpful at that time as I remember and the old posts says. But it is not working now.
Here is the simplified code that adds and removes a marker by button clicked. As you can see, you have to resize the frame to see the change. (Only the first addition is shown immediately as you add)
How can I force update?
[Environment]
Windows 10
Python 3.9.6
wxPython 4.1.1
The fun part is that not even “self.canvas.Redraw” is necessary to the (non-)functioning of your example. If you comment it out, you’ll see that your code will work just the same. So, apparently “Redraw” does not redraws at all, at least not the way it’s supposed to.
The frustrating part is that the canvas won’t respond to a “SendSizeEvent()” either, a trick that usually works in such cases.
Now, from a cursory glance at the code of the examples, it looks like wx.lib.plot is intended for “static” plots only, and there are no hooks for updating “on the fly” an already existing graph. Of course, nothing stops you from erasing all the content and start over… but if you need frequent updates (say, a “live” graphic plotting from a data stream) then you will end up with some flickering I’m afraid.
You should probably dig in the source code and find out what exactly happens in response to a EVT_SIZE (since this is when your plot get updated, apparently) and see if you can trigger the same thing on demand. And while you’re at it, perhaps also take a look at that “Redraw” thing, and figure out what it really does.
omg, it is true that I even don’t need “Redraw().”
I will look into EVT_SIZE as you mentioned.
By the way, do you have any recommended sight-package for ‘live’ plotting? I use Matplotlib usually but it it not good for live at all.
Not sure what you need for “live” plotting, but I’ve discovered a way to make “oscilloscope” type plots with Matplotlib with fairly rapid re-plotting. Here’s an example: oscope.py (473 Bytes)
This runs pretty fast on my machine using the WxAgg backend.
Had the same issue where I was regenerating plots but the matplot canvas would only update whenever I resized the wxPython frame.
Tried generating resize events, or plt.show(), redraw() etc etc. but none of this helped.
Not sure why but setting matplotlib to interactive mode ( matplotlib.pyplot.ion() ) solved the issue for me. (I used TkAgg as backend)