Updating AxesImage objects (.imshow(), .pcolormesh()) of matplotlib. #3449
Potescito
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
Hi 😊, I recently stumbled upon something interesting when I was attempting to update the data of an AxesImage instance, which differs from updating a standard 2D matplotlib plot. I will describe what I have done in case someone faces the same issues.
*The basic idea: I want to continuously show image frames coming from a sensor device, using matplotlib, not opencv.
Initial example (snippet):
Now, let's assume I have an asynchronous function that retrieves the frames:
Guided by the nicegui documentation and this discussion post: #55 (comment), I attempted to use
ui.update()
to refresh the image plot with new data, but this approach did not work and, in fact, there is no need ofui.update()
. Interestingly, even after setting the new data successfully, the plot failed to refresh. The only way in which I could make it work was by either updating the plot's color limits along with the new frames:refs.img.set_clim((refs.frame.min(), refs.frame.max()))
, or by defining the limits upon the AxesImage object instantiation, if they are known:refs.img = ax.imshow(refs.data, vmin=0, vmax=255)
. After that, the plot updates every time there is a new frame, without the need of recalling_img_plot.refresh(refs)
.I hope this will be helpful to someone! 😊
Beta Was this translation helpful? Give feedback.
All reactions