Can you make mpld3-matplotlib interactive ?
what I mean is display a graph on a web page and be able to update the time series i.e. not simply static graph, but dynamic one page graph-app ?
What can be leveraged from mpld3 ?
if you don't have to support matplotlib then an option is Bokeh or Dash library instead.
Related
I have an interactive graph generated by Plotly in Python that I saved to an html file using plotly.offline.plot(fig, filename='/tmp/interactiveGraph.html')
I am now trying to embed this interactive graph into some kind of webpage, using either Dash or Django. I'm leaning toward Django at the moment, given that I have an html version of the graph. Which would be better?
My code for the webpage is in a separate file from the code where I am creating the graph.
A lot of the tutorials I've found online just say to add a few lines to the template, but I don't know how to get those lines that they've described.
tl;dr: I'm looking for guidance as how to integrate an html file-for a Plotly interactive graph-with a web python script using Django or Dash
Side Question:
what is the difference between
plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
and what I have above?
Reference:
https://github.com/ricleal/DjangoPlotLy
https://www.pythonsetup.com/how-implement-data-visualization-django-and-plotly/
I would highly reccomend Django, its a great framework. As for this, the best option is to generate the data via JavaScript and Plotly has a great library for this. If you must use python, then Django can be used. Assuming you are familiar with Django, inside of your view you can collect your data and build your graph ( I would reccomend a celery task for something long running like this unless they are small graphs), and you can then collect the return from creating the graph in div format. This will return a string that holds all the needed html and css for the graphs. Put this inside of you get_context_data() method in your view and place it into the dictionary. You can the use that object inside of a template. I have done this before, if you are having a hard time feel free to DM me. Hope this helps some!
In regards to your side question, I believe having False for including JS will make the graph a bit smaller assuming you have an include for the plotly JS library. They might have done this in a newer release to make the graphs faster as they were significantly slower in the browser from python that the JS rendered one.
So, I'm learning how to use matplotlib and stumbled into MPLD3 as the most used way to get these plots in a webpage. However, MPLD3 doesn't support tick formatting and that's something critical for the project I'm in right now. I'd like to know if there is another way to add a matplotlib graph to a webpage while keeping the tick formatting and also having tooltips to display data on hover.
Thanks!
For a web application I would consider bokeh. You can output html with interactive charts or run another backend server. If you go to the ipython notebook tutorial section 10 has demos for embedding.
Alternatively you can just save images from matplotlib and use them as static assets in your page.
I'd like to output the image to the web created in matplotlib having the very same functionality like it has on desktop when you run the image.show(), for example scaling, moving along the plot more thoroughly.
I've checked out #stack and got old post only offering static images or gif or matplotlib.animate()
I aslo had a look at matplotlib widgets, but those are for desktop GUI only as far as I can see.
Please share some experience or ideas regarding how can I achieve it.
Thanks
Matplotlib is a server side library so you cannot do anything on the client side like that.
The closest you can come is to either use mpld3 (mpld3 works by converting a matplotlib graph into the html/js that a d3 js graph would need to render) or a different client side library that plots points.
The easiest way of serving pure matplotlib to the web is using a jupyter notebook.
Other than that, you may want to look at specific libraries like Plotly or bokeh.
I have a Flask web app that uses Bokeh to deliver interactive charts. My end goal is to export whatever the current Bokeh view is to Matplotlib (so that I can create a printable pdf file after that). This would include how the current axes look like after the user zooms and pans. Is there a way to export that data so that I can create those Matplotlib charts behind the scenes? (Printing the page directly or printing to pdf results in low-quality and blurred charts.)
Thanks!
No, currently there is no way to export bokeh to matplotlib. Actually you can do it otherway. You can create matplotlib plot, save, and after that you can export matplotlib to bokeh. I think this is the best option. Eventually you can export bokeh plot as png but it still would not solve problem with quality
I am using bokeh to plot my math functions created with python/numpy.
I would like to use sliders as shown in
http://docs.bokeh.org/en/latest/docs/server_gallery/sliders_server.html
Once I create the html file with the plot, I would like to select different values on the sliders which modify the plot and then read back the chosen values in into python to use it for other manipulations.
What is the best way to read the chosen value on the slider from the html file back into python ?
I saw pyquery could be useful, but I cannot really figure that out.
Any suggestions would be appreciated based on above scenario.
There are two slider examples in the bokeh repo, where the slider is connected back to python via the bokeh server.
Sliders App
Taylor server
If this isn't what you were after, can you elaborate a little more?
A static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server - answered via bokeh-google group