Data Visualization is a fun but pretty complex part of Data Science. Getting it right is very important and we put a lot of focus on it in our online bootcamp. As far as the visualization in Python goes, Matplotlib usually gets you pretty far with reasonable effort. Problems usually arise once you want to show your graphs to someone else (make them more appealing, interactive, and share them with your colleagues). Here is where Matplotlib will cost you hundreds of lines of code and lots of effort.

Today, I will introduce you to Plotly, a great open source tool for building interactive visualizations built on top of Javascript and D3. So let's get started.
 

GET A PLOTLY ACCOUNT

Before we start head over to the Plotly page and register there for a FREE account. Your Account stays free forever, with certain limitations: There is a limited amount of requests you can send through the API per day, and all your plots will be publicly visible.
 

INSTALL & SET UP PYTHON PACKAGE

You can install Plotly easily through pipJust run in your terminal:

pip install plotly

Once that is done, you can import and setup your Plotly credentials within Python. You can find your Plotly login here.

import plotly 
plotly.tools.set_credentials_file(username='DemoAccount', api_key='lr1c37zw81')

Now you are ready to get plotting!
 

FIRST PLOT

To show you the first plot, we borrowed a dummy example from the Plotly website:

import plotly.plotly as py
import plotly.graph_objs as go

import pandas as pd
import numpy as np

# Generate random data
N = 40
x = np.linspace(0, 1, N)
y = np.random.randn(N)
df = pd.DataFrame({'x': x, 'y': y})
df.head()

# Create plot
data = [
    go.Bar(
        x=df['x'], # assign x as the dataframe column 'x'
        y=df['y']
    )
]

# IPython notebook
py.iplot(data, filename='pandas-bar-chart')

This will display the following graph in your Jupyter Notebook:

plotly_hist

Congrats, you just made your first Plotly graph.
 

OKAY, THAT'S NEAT. SO WHAT?

Not particularly impressed? You are right. The graph looks neat, it is what you would expect, but not much else. So what's the big deal?

There might be a couple of things that escape your sight at first. If you try to hover over your data, you will realize that the whole plot is interactive. You have annotations on your points and the plot is zoom-able.

We still promised you sharing right? To achieve that, you just replace the last line in the code above with this:

url = py.plot(data, filename='pandas-bar-chart')

Instead of being embedded in your notebook, Plotly opens up a new tab such as this one. It is your own visualization hosted on a server. Not only can you share it with anyone, you can also play around and edit it directly in the Plotly platform.
 

WHAT'S NEXT?

I hope you are sold. If you want to know more, check out the Plotly documentation, there are plenty of examples of how to make scientific charts, plots, maps, dashboards and other visualization tools you might need. If you don't know where to start, check out our Basecamp.ai bootcamp for more Data Science education.