plt in ui.view
Most plt examples either display the plot in the console or save the image and display in ui.imageview().
Is there a way to show it in a ui.view() without first saving a plt image?
For example, what if I wanted an animated plot in a ui.imageview()?
I would be interested in this as well - I've used matplotlib to make static images of plots, but would love to hear any suggestions for real time animated graphs.
Are you using the beta, or 1.5?
In the beta, see, for example:
which uses some objc gesture recognizers.
and in 1.5, see
which uses a custom View with touch handling that should work in 1.5 as well . This one was specific to someone's specific plotting needs, but has an improved threading approach if my memory serves.
Both use a threaded approach to generating matplotlib plots and updating an imageview.
Some of these ideas might be useful.
The key is to use plt.savefig with a bytesio object that you can pass to the renderer. Using jpg and a lowish dpi allows near real time pan/zooming for example. Animations probably could be possible, as long as you are updating the data and/or axes, and not generating a whole new plot, which is slow. Once the user has stopped zoom/panning, you can the render the full res image.
edit: i see my mplview example is not fully functioning. I think I had a forum post showing a more generic version.
Thank you @JonB. I am using 1.5 ( I avoided the beta to reduce bugs in my projects, can't wait for official update!)
I figured there was no way to show animations directly in a ui.view. Even support for a gif animation would help.
By the way, no plot animation examples animate using plt.show() in the console. 1.5 must not be setup for that.
Animations are not automatic, nor do gif animations work in imageviews. Essentially you can update the image view image as you go. or you can show animated gifs in a webview
Oh! That's it! Animated GIFs will play in a
web_view()won't they? That will work for me! And yes, I guess I could just update a series of images too...
Yes, they will. Just place them in a folder with the html file, and use abspath along with load_url (iirc you don't need file://, just the full path to the filename) then the html file can use relative path names to refer to the images.
Excellent information. Thank you.