Closed nilsbecker closed 6 years ago
Yes, mlab
uses gr.adjustlimits
to produce round limits and I agree, this does not work for side-scrolling animations as they should be smooth. I will add a flag to disable it.
For now, you can manually replace gr.adjustlimits
itself:
gr.adjustlimits = lambda x_min, x_max: (x_min, x_max)
ah, that seems easy enough! will try. btw, is pygr.mlab actually redundant now that gr supports acting as a matplotlib backend? should i use that instead ?
update: the scrolling is now working better! unfortunately, still a bit irregular but that may be to the actual data updates. is time.sleep
the preferred way to pause in such an animation?
For me it went from being incredibly choppy to very smooth, but the example I used was very simplified:
import gr
from gr.pygr import mlab
gr.adjustlimits = lambda x_min, x_max: (x_min, x_max)
for t in range(1000):
x = [0.1+t*0.001, 0.172+t*0.001]
y = [0, 1]
mlab.plot(x, y, xrange=(x[0], x[1]))
Instead of updating the x limits whenever new data is available try to change the limits at a fixed rate, if that's possible with your data, that way a little empty space might be shown at the right side of the plot now and then, but it won't "jump" to the right once the data becomes available.
How you pause is completely up to you, time.sleep
should work fine.
The matplotlib backend existed before the mlab
module was created as a matlab-ish interface to gr. Personally I use mlab
for simple/"normal" plots and switch to pure gr for less generic images.
ok, thanks! my data are definitely inherently choppy. the smooth limit update might be feasible but it would require some fancy smooth adaptive speed control -- too much work for the moment.
i am trying to produce a live-updating plot of some running molecule number statistics via mlab. i want to include a time axis on the x-axis, which is also updated live. for this, i have to reset the xlim limits in each update step to the exact extent of the time data. however, mlab snaps the limits to some 'round' values, which makes the updates choppy. is there a way to prevent that?
code:
here,
matimes
andmanumbers
are live-updated buffers.