Skip to content

Instantly share code, notes, and snippets.

@fperez
Created February 11, 2014 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fperez/8930306 to your computer and use it in GitHub Desktop.
Save fperez/8930306 to your computer and use it in GitHub Desktop.
Illustrating the properties of statistical distributions with numpy and plotly
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:a338666f9bb017a14aa7b5b4d1016458edcaf406f4b825f6e403014714ec88dc"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"import numpy.random as nr\n",
"import plotly\n",
"py = plotly.plotly('IPython.Demo', '1fw3zw2o13')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"distributions = [nr.uniform, nr.normal , lambda size: nr.normal(0, 0.2, size=size),\n",
" lambda size: nr.beta(a=0.5, b=0.5, size=size),\n",
" lambda size: nr.beta(a=0.5, b=2, size=size)]\n",
"\n",
"names = ['Uniform(0,1)', 'Normal(0,1)', 'Normal(0, 0.2)', 'beta(a=0.5, b=0.5)', 'beta(a=0.5, b=2)']\n",
"\n",
"boxes = [{'y': dist(size=50), 'type': 'box', 'boxpoints': 'all', 'jitter': 0.5, 'pointpos': -1.8,\n",
" 'name': name} for dist, name in zip(distributions, names)]\n",
"\n",
"layout = {'title': 'A few distributions',\n",
" 'showlegend': False,\n",
" 'xaxis': {'ticks': '', 'showgrid': False, 'showline': False}\n",
" 'yaxis': {'zeroline': False, 'ticks': '', 'showline': False},\n",
" }\n",
"\n",
"py.iplot(boxes, layout = layout, filename='Distributions', fileopt='overwrite', width=1000, height=650)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<iframe height=\"700\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/1101/1000/650\" width=\"1050\"></iframe>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 46,
"text": [
"<IPython.core.display.HTML at 0x2d74110>"
]
}
],
"prompt_number": 46
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment