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.

You'll want to have version 1.0.0. If not, run $ pip install plotly --upgrade in a terminal. Check out our User Guide for more details on where to get your key. Problems or questions? Email feedback@plot.ly or find us on Twitter.

Loading output library...

I. matplotlib Gallery graphs

#I.-matplotlib-Gallery-graphs

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.

You control the privacy by setting world_readable to False or True, and can control your sharing.

Let's get started with this damped oscillation graph.

Loading output library...

Now, to convert it to a Plotly figure, this is all it takes:

Loading output library...

You can hover, zoom, and pan on the figure. You can also strip out the matplotlib styling, and use Plotly's default styling.

Loading output library...

Next up, an example from pylab.

Loading output library...

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.

Loading output library...

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:

https://plot.ly/~IPython.Demo/3357/

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.

Loading output library...

We also keep the data and graph together. You can analyze it, share it, or add to other plots. You can append data to your plots, copy and paste, import, or upload data. Take-away: a Python user could make plots with an Excel user, ggplot2 Ploty package, and MATLAB user. That's collaboration.

Loading output library...

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.

Loading output library...

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.

Loading output library...

Where it remains interactive. That means your for-free defaults are: D3 graphs, drawn with JavaScript, and shared data. Here's how it looks in the Washington Post.

Loading output library...

It's fun to zoom. Then double-click to re-size.

Loading output library...

Plots can be collaboratively edited and shared with others.

Loading output library...

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/.

Loading output library...

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.

Loading output library...

Another subplotting example using Plotly's defaults.

Loading output library...

From the gallery here we're shwoing Anscombe's quartet. You might also like Plotly's blog post on the subject.

Loading output library...

And a final histogram from the matplotlib gallery.

Loading output library...

Want to see more matplotlylib graphs? Head over to our API and copy and paste away.

Loading output library...

II. ggplot for Python

#II.-ggplot-for-Python

An exciting package by Greg Lamp and the team at ŷhat is ggplot for Python. You can draw figures with ggplot's wonderful syntax and share them with Plotly. You'll want to run $ pip install ggplot to get started.

We'll start out with a plot from the diamonds dataset.

Then share it to Plotly.

Loading output library...

Line charts can be interactive (drag your mouse along the line to see the data on the hover).

Loading output library...

Histograms are also fun to hover over to get the exact data.

Loading output library...
Loading output library...

You can also use more advanced plotting types in collaboration with pandas. You can add a geom.

Loading output library...

III. Prettyplotlib graphs in Plotly

#III.-Prettyplotlib-graphs-in-Plotly

The lovely gallery of examples from prettyplotlib, a matplotlib enhnacing library by Olga Botvinnik, is a fun one to make interactive. Here's a scatter; let us know if you make others. You'll note that not all elements of the styling come through. Head over to the homepage for documentation.

Loading output library...

And another prettyplotlib example.

Loading output library...

IV. Plotting with seaborn

#IV.-Plotting-with-seaborn

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.

Loading output library...

You can also run subplots like this.

Loading output library...

And a final example, combining plot types.

Loading output library...

V. Stack Overflow Answers

#V.-Stack-Overflow-Answers

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.

Loading output library...

Here is how to create a density plot like you might in R, but in matplotlib.

Loading output library...

Drawing a simple example of different lines for different plots looks like this...

Loading output library...

...and can get more exciting like this.

Loading output library...

Plotly also lets you draw variables as subscripts in math mode.

Loading output library...
Loading output library...