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!
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
We are generating a 1D dataset from a Weibull Distribution
which has the distrubution
where $U$ is drawn from the Uniform Distribution
.
x=np.random.weibull(1.25, size=1000)
print(x[:10])
[ 0.86317076 0.79217698 2.07432654 0.70721605 0.24102326 1.44261213 0.85526797 1.0158948 1.19976016 1.78112064]
By using a histogram, we can properly divide a 1D dataset into bins with a particular size or width, so as to form a discrete probability distribution
trace = go.Histogram(x=x, xbins=dict(start=np.min(x), size=0.25, end=np.max(x)),
marker=dict(color='rgb(0, 0, 100)'))
layout = go.Layout(
title="Histogram Frequency Counts"
)
fig = go.Figure(data=go.Data([trace]), layout=layout)
py.iplot(fig, filename='histogram-freq-counts')
We can experiment with our bin size and the histogram by grouping the data into larger intervals
trace = go.Histogram(x=x, xbins=dict(start=np.min(x), size=0.75, end=np.max(x)),
marker=dict(color='rgb(0, 0, 100)'))
layout = go.Layout(
title="Histogram Frequency Counts"
)
fig = go.Figure(data=go.Data([trace]), layout=layout)
py.iplot(fig, filename='histogram-freq-counts-larger-bins')
from IPython.display import display, HTML
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
'python-Frequency-Counts.ipynb', 'python/frequency-counts/', 'Frequency Counts | plotly',
'Learn how to perform frequency counts using Python.',
title='Frequency Counts in Python. | plotly',
name='Frequency Counts',
language='python',
page_type='example_index', has_thumbnail='false', display_as='statistics', order=2,
ipynb= '~notebook_demo/111')
Collecting git+https://github.com/plotly/publisher.git Cloning https://github.com/plotly/publisher.git to /var/folders/ld/6cl3s_l50wd40tdjq2b03jxh0000gp/T/pip-ctBFME-build Installing collected packages: publisher Found existing installation: publisher 0.10 Uninstalling publisher-0.10: Successfully uninstalled publisher-0.10 Running setup.py install for publisher ... - \ done Successfully installed publisher-0.10
/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead. "You should import from nbconvert instead.", ShimWarning) /Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you "Save" this notebook before running this command? Remember to save, always save. warnings.warn('Did you "Save" this notebook before running this command? '