Generating animation in the browser using matplotlib - python

Let me describe the background first:
We have a python package that uses matplotib to create animations.
Currently, we use this package to create gifs, which we embed into our website.
In the future, the number of animations will increase, so that we are looking for a way to create these gifs only dynamically when a user wants to see a gif. Preferably, these animations will be created in the browser using the CPU of the user. I have seen that mpld3 can be used to create visualizations, however, animations are not supported and it is using our CPU.
This leads me to the question: Does someone know about a way to generate animations from matplotlib code in the browser preferably using the CPU of the user (not a must have)? Maybe is there a way of using jupyter notebooks for that?

Related

Jupyter - widget to play audio with playhead on graph

Is there any Jupyter widget for visualizing audio synced with a playhead on a time-series plot?
I would like to visualize data derived from an audio sample (e.g. spectrogram and various computed signals), listening to the audio sample while seeing the playhead move across the plots.
I found this old gist https://gist.github.com/deeplycloudy/2152643 which uses pyaudio on the Python backend to play the sound. Any good solutions out there that are a bit less hacky, e.g. ideally entirely JavaScript-based and with playback running fully in the browser?
You can now :). It took me about 10 minutes to put together a demo using Jupyter proxy widget to load a wavesurfer control into a notebook. It works in Chrome but I haven't tested it anywhere else. It should work anywhere wavesurfer and Jupyter work.
Here is a screenshot
See the pastable text from the notebook here:
https://github.com/AaronWatters/jp_doodle/blob/master/notebooks/misc/wavesurfer%20demo.ipynb
For information on jp_proxy widgets look here:
https://github.com/AaronWatters/jp_proxy_widget
In the time since I posted this question, a few new solutions have emerged:
Scott Condron: Building Tools to Interact With Your Data
Building Tools to Interact With Your Data 2020-10-21-interactive-audio-plots-in-jupyter-notebook.ipynb
These solutions use holoview, have a playhead linked between the audio and the plots, and can run fully on the browser.

Create a basic Python interface to save images drawn with a mouse

I am working on the following project and I am having really difficulties in finding the right way of doing that. I would like to build in Python (but I am open to other possibilities) a very basic interface that allows the user to draw with the mouse (or the pen if used on a surface laptop) something and then save the image. Ideally I would like this to work on a website or at least in a jupyter notebook (at least I imagine this to be utterly difficult).
Anyone can point me in the right direction? The goal would be to use the images as input to a neural network model to demonstrate its result with real life examples.
I am looking at tk but I don't seem to find much in terms of examples.
Thanks in advance, Umberto
I'd take a look at pyautogui to capture the mouse location then "draw" it in matplotlib -- should be able to do this in a loop. You'll want to watch the tkinter window size to sync the mouse coordinates with the relative location.
Why not just have your script open create a new blank img and automatically open it with paint - then read it on close? Seems easier than creating a drawing GUI.
Have a look at my Github repository which have exactly what you need.
Link : CanvasDraw Repo
Depending on the complexity you could either use tkinter which is a package for complex GUIs or something from the gaming community like pygames. You have user input and graphical output so libraries made for games will do what you want but provide way more stuff then you need. This site might help you: Drawing Libarys
Also the answere draw-on-python-tkinter-canvas-using-mouse-and-obtain-points-to-a-list might help you.

Interactive tooltips in matplotlib plot

Is there any way of getting interactive tooltips in a matplotlib plot? For instance, I wanted to get this scatter plot with hovering tooltips (http://mpld3.github.io/examples/scatter_tooltip.html) functionality in my python application, because they are really useful for visualizations. Unfortunately, I do not want to show this in a browser, but integrated in my own python application, is there any way to do this?
Matplotlib can only create static images and animations. If you want something interactive, then the only way you're going to achieve this is by using a module that outputs javascript. I would suggest reading about bokeh.
It is well developed and gaining a lot of traction in the python world as being a good option for creating interactive plots. Here's an example of bokeh's hovertool capability.
Unfortunately, I do not want to show this in a browser, but integrated in my own python application
I'm not sure what your "own python application" is but you're not going to have a fun time making an interactive plot outside of a browser. I would highly suggest going a webapp route using bokeh if interactivity is truly important to you.

Is there a way to get every frame of a GIF animation in Python?

I'm developing an engine with Python and Pygame, and it already has built-in support for animations with spritesheets. Nevertheless, It would be really interesting to be able to get the frames from a gif so that I could add to the Animation object as an alternative to spritesheets.
Is there a library to access the frames in a gif file, or even video, in Python? Thank you very much.
Check out MoviePy.
MoviePy is a Python module for script-based movie editing. It enables basic operations (cuts, concatenations, title insertions) to be done in a few lines, and can be used for advanced compositing and special effects.
http://zulko.github.io/moviepy/
Also, here is a tutorial on how to use it to make gifs, which could prove useful:
http://zulko.github.io/blog/2014/01/23/making-animated-gifs-from-video-files-with-python/

Python Graphviz Editor or GUI Framework

I have written a python application which generates output in graphviz DOT format. I convert the generated file into PNG using the external 'dot' utility and open the generated PNG in an image viewer to visualise the graph.
My application is an interactive command-line tool which allows few operations on the graph like changing the colours of edges based on the edge weights, deleting few nodes, etc. After these operations I generate the DOT file again and convert it to PNG for visualisation.
I came across xdot.py which allows me to embed the interactive viewer into my application. Now I do not have to go to the shell to generate the PNG every time.
I want to take this idea further and build a full-fledged GUI application on top of this. I have few questions regarding this:
Do I have to start from scratch (use wxPython or any other GUI framework)? Use a canvas to display the generated image and refresh it whenever there are operations performed on the graph.
Is there any other package which serves this purpose? I am looking for some package which can edit the graph and just provide me with the ability to bind my graph operations to the mouse events on the viewer.
Any other ideas? Greatly appreciate your inputs.
wxPython can display images very easily using wx.StaticBitmap. Here's a tutorial on the subject:
http://www.blog.pythonlibrary.org/2010/03/26/creating-a-simple-photo-viewer-with-wxpython/
You will probably need to do something like this:
img = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY,
wx.BitmapFromImage(img))
Then just refresh it whenever you update the image. Depending on your graphing needs, there is the matplotlib project which can be integrated into wxPython.
There is a project that use wxPython and pydot that you might find useful: http://code.google.com/p/pyflowuca/. I saw it mentioned here: http://pythonhaven.wordpress.com/2009/12/09/generating_graphs_with_pydot/

Categories

Resources