Plotly is collaborative, makes beautiful interactive graphs with a URL for you, and stores your data and graphs together. This NB shows how to use Plotly to share plots from some awesome Python plotting libraries. The matplotlylib project is a collaboration with mpld3 and Jake Vanderplas. We've put together a User Guide that outlines the full extent of Plotly's APIs.
For best results, you can copy and paste this Notebook and key. Run
$ pip install plotly inside a terminal then start up a Notebook. We'll also be using ggplot, seaborn, and prettyplotlib, which you can also all install form pip. Let's get started.
You can use our public key and username or sign up for an account on Plotly. Plotly is free for public use, you own your data, and you control the privacy.
For matplotlib experts, you'll recognize these graphs from the matplotlib gallery.
In addition to matplotlib and Plotly's own Python API, You can also use Plotly's other APIs for MATLAB, R, Perl, Julia, and REST to write to graphs. That means you and I could edit the same graph with any language. We can even edit the graph and data from the GUI, so technical and non-technical teams can work together. And all the graphs go to your profile, like this: https://plot.ly/~IPython.Demo.
Now, to convert it to a Plotly figure, this is all it takes:
You can hover, zoom, and pan on the figure. You can also strip out the matplotlib styling, and use Plotly's default styling.
Here's where this gets special. You can get the data from any Plotly graph. That means you can re-plot the graph or part of it, or use your favorite Python tools to wrangle and analyze your data. Check out our getting started guide for a full background on these features.
Or you can get the figure makeup. Here, we're using 'IPython.Demo', which is the username and '3357' which is the figure number. You can use this command on Plotly graphs to interact with them from the console. You can access graphs via a URL. For example, for this plot, it's:
Now let's suppose we wanted to add a fit to the graph (see our fits post to learn more), and re-style it a bit. We can go into the web app, fork a copy, and edit the image in our GUI. No coding required.
I can now call that graph into the NB. I can keep the styling, re-use that styling on future graphs, and save styles from other graphs. And if I want to see the data for the fit or access the figure styling, I can run the same commands, but on the updated figure and data for this graph. I don't need to re-code it, and I can save and share this version.
Plotly graphs are always interactive, and you can even stream data to the browser. You can also embed them in the browser with an iframe snippet.
It's fun to zoom. Then double-click to re-size.
Plots can be collaboratively edited and shared with others.
So you can keep all your plots for your project, team, or personal work in one plce, you get a profile, like this: https://plot.ly/~jackp/.
You can also plot with Plotly with pandas, NumPy, datetime, and more of your favorite Python tools. We've already imported numpy and matplotlib; here we've kept them in so you can simply copy and paste these examples into your own NB.
Another subplotting example using Plotly's defaults.
We'll start out with a plot from the diamonds dataset.
Then share it to Plotly.
Line charts can be interactive (drag your mouse along the line to see the data on the hover).
Histograms are also fun to hover over to get the exact data.
You can also use more advanced plotting types in collaboration with pandas. You can add a geom.
And another prettyplotlib example.
Another library we really dig is seaborn, a library to maximize aesthetics of matplotlib plots. It's by by Michael Waskom. You'll need to install it with
$ pip install seaborn, and may need to import six, which you can do from pip. The styling isn't yet translated to Plotly, so we'll go to Plotly's default settings.
You can also run subplots like this.
We love Stack Overflow, so wanted answer a few questions from there, in Plotly. If you want to plot data you already have as a histogram and make it interactive, try this one out.
...and can get more exciting like this.