I have been searching how to embed an interactive matplotlib widget (like this one: http://matplotlib.org/examples/widgets/slider_demo.html) in a webpage. The final aim is to make an educational page.
I hope I am not duplicating the question. What google finds is always how to embed the plot as a still-shot, in an image format.
I thought I can do something with ipython notebook or plotly or gjango. But I got confused.
Is it possible at all for intractive plots?
I appreciate your guides to which direction I should think and work on.
Thank you.
In summer 2015, I'm facing a similar task: embed interactive widgets that change their underlying data when the slider is moved. This is very similar to interactive IPython widgets which are interactive when run on a local machine. Examples of what I want can be found jakevdp's blog.
To summarize work done so far:
ipywidgets-static converts interactive IPython widgets to static HTML. However, this library is no longer maintained. Development has moved to ipython/ipywidgets.
IPython is working on ipython/ipywidgets. They have a Github issue to make these widgets static and to be embedded in a standalone HTML file.
HoloViews provides some interactive slider options that can be embedded in a static HTML file (using IPython's nbconvert)
Bokeh plots that rely on interactive sliders require a server.
plot.ly doesn't support sliders/etc. I believe this is true based off this blog post.
mpld3 converts between matplotlib and d3. I believe this library supports panning and zooming, not sliders/interactivity. Here's a related Github issue
There's also blog post titled "Scientific Python in the browser: it's coming!". This post was dated 2014-3-31.
For me, the two most attractive options are ipywidgets and HoloViews but I'm looking forward to when IPython provides static interactive widgets. I expect to see solid support for static interactive widgets quickly and in less that 5 years/2020 (and in 2 years/2017?).
As of Early April 2014 the answer is yes. Based on the work going on in this space, I expect the quality and quantity of such libraries to continue to improve very quickly.
IPython 2.0, specifically the notebook, supports interactive controls, which was covered in some detail by Brian Granger in his talk IPython - The Attributes of Software and How They Affect Our Work (see from 32:25 onward for the bits you're interested in)
There are some amazing projects being worked on at the moment that combine server and client side code for the next generation of python visualisation libraries. At the moment this includes the work on MPLD3 and the ipywidgets library. There are some great interactive plots on Jake Vanderplas' blog Pythonic Perambulations that show demonstrate this.
Related
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.
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?
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.
I'd like to know if a matplotlib chart be interactive, ie when you right click on a graph bar, a context menu opens, then you click one of the menu items and change the value of y value or you drag the top edge of the bar with mouse and it becomes taller etc,
In other words, can a matplotlib chart act like a GUI?
yep, though I should warn you: matplotlib isn't the best choice for interactive tasks. Depends on your tasks you may face performance or UX issues..
Take a look at the Chaco. It was designed for the creation of complex interactive plots.
Yes.
Matplotlib is based on Tkinter, so you can do all sorts GUI related things with it. For an example of how you can embed matplotlib in a Tkinter GUI see here:
http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html
Similarly for the functionality you are describing, you require plots that know when they've been clicked on (or mouse-overed) and that you can add callback events to. For that, the first place to look would be picker events:
http://matplotlib.org/examples/event_handling/pick_event_demo.html
As an alternative to some of the other ideas I would propose the Ipython notebook. For me it is the easiest way to do some of the things your asking about without having to get into Tkinter etc.
From Ipython 2.* onward there are interactive widgets allowing you to interact with the kernel from a GUI. I am not an expert in any sense so it is probably best explain by Fernando Perez himself.
Here is an example of interaction when solving the Lorenz differential equation demonstrating a chaotic system. This is accessible in the example of the ipython directory.
I want to visualize some measurement values in realtime. I think - although not finally sure - I can do this with PyChart. The surrounding application is based on PyQt.
Now I', wondering how I can put the chart drawn using PyChart into some qt widget, may be a QGraphicWidget?
Could someone give me a bit advise?
Cheers,
Wolfgang
I have learned to do this by following the instructions of Eli Benderski.
It is answered here on this site in this thread
Demo Code is here
This uses matplotlib instead of PyChart. Usage of matplotlib is well documented here.
Matplotlib allows you to interact with the plot canvas as well as importing a Navigation Tool Bar.
Hope this is helpful.