Show Sidebar Hide Sidebar

Statistics Charts in Python

Learn how to plot statistical data with various charts using Python.

New to Plotly?

Plotly's Python library is free and open source! Get started by dowloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

Imports

The tutorial below imports NumPy, Pandas, and SciPy.

In [1]:
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.tools import FigureFactory as FF

import numpy as np
import pandas as pd
import scipy

Import Data

For this example we will use some real data of wind speeds sampled every 10 minutes.

In [2]:
wind_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/wind_speed_laurel_nebraska.csv')
df = wind_data[0:10]

table = FF.create_table(df)
py.iplot(table, filename='wind-data-sample')
Out[2]:

Histogram

We will be producing a histogram with the "10 Min Std Dev" column of our data. For more info on the histogram charts, you can checkout the documentation page.

In [3]:
data = [
    go.Histogram(
        x=wind_data['10 Min Std Dev'],
        histnorm='probability'
    )
]
py.iplot(data, filename='wind-data-histogram')
Out[3]:

Box Plots

We will be producing a box plot with the "10 Min Std Dev" column of our data again. For more info on the histogram charts, you can checkout the documentation page.

In [4]:
data = [
    go.Box(
        y=wind_data['10 Min Std Dev'],
    )
]

py.iplot(data, filename='wind-data-box-plot')
Out[4]:

Scatterplot Matrix

We will be producing a scatterplot matrix with all the columns of our data. For more info on the histogram charts, you can checkout the documentation page.

In [5]:
fig = FF.create_scatterplotmatrix(wind_data,
                                  height=1000,
                                  width=1000,
                                  title='Wind Data - Scatterplot Matrix')
py.iplot(fig, filename='wind-data-scatterplot-matrix')
This is the format of your plot grid:
[ (1,1) x1,y1 ]  [ (1,2) x2,y2 ]  [ (1,3) x3,y3 ]
[ (2,1) x4,y4 ]  [ (2,2) x5,y5 ]  [ (2,3) x6,y6 ]
[ (3,1) x7,y7 ]  [ (3,2) x8,y8 ]  [ (3,3) x9,y9 ]

Out[5]:
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.