Skip to content

Commit 32dffaa

Browse files
author
Christopher Fonnesbeck
committed
Added notebooks for Pandas and PyMC plotting
1 parent cec6d7b commit 32dffaa

File tree

2 files changed

+612
-0
lines changed

2 files changed

+612
-0
lines changed

Pandas + Plotly.ipynb

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"metadata": {
3+
"name": ""
4+
},
5+
"nbformat": 3,
6+
"nbformat_minor": 0,
7+
"worksheets": [
8+
{
9+
"cells": [
10+
{
11+
"cell_type": "code",
12+
"collapsed": false,
13+
"input": [
14+
"import plotly"
15+
],
16+
"language": "python",
17+
"metadata": {},
18+
"outputs": [],
19+
"prompt_number": 1
20+
},
21+
{
22+
"cell_type": "code",
23+
"collapsed": false,
24+
"input": [
25+
"reg = plotly.signup('pandas_and_plotly_demo', '[email protected]')"
26+
],
27+
"language": "python",
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"output_type": "stream",
32+
"stream": "stdout",
33+
"text": [
34+
"Thanks for signing up to plotly!\n",
35+
"\n",
36+
"Your username is: pandas_and_plotly_demo\n",
37+
"\n",
38+
"Your temporary password is: 3eowi. You use this to log into your plotly account at https://plot.ly/plot.\n",
39+
"\n",
40+
"Your API key is: e39otewkg2. You use this to access your plotly account through the API.\n",
41+
"\n",
42+
"To get started, initialize a plotly object with your username and api_key, e.g. \n",
43+
">>> py = plotly.plotly('pandas_and_plotly_demo', 'e39otewkg2')\n",
44+
"Then, make a graph!\n",
45+
">>> res = py.plot([1,2,3],[4,2,1])\n",
46+
"\n",
47+
">>> print(res['url'])\n",
48+
"\n"
49+
]
50+
}
51+
],
52+
"prompt_number": 3
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"This simple example shows how easy it is to generate plot data from Pandas' `groupby` method. Using the Titanic passenger dataset, we can easily generate a boxplot of age distribution by passenger class."
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"collapsed": false,
64+
"input": [
65+
"import pandas as pd\n",
66+
"\n",
67+
"titanic = pd.read_csv(\"http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic3.csv\")"
68+
],
69+
"language": "python",
70+
"metadata": {},
71+
"outputs": [],
72+
"prompt_number": 4
73+
},
74+
{
75+
"cell_type": "code",
76+
"collapsed": false,
77+
"input": [
78+
"age_by_class = [{'y': data.values, \n",
79+
" 'name': pclass,\n",
80+
" 'type': 'box',\n",
81+
" 'boxpoints': 'all', \n",
82+
" 'jitter': 0.3} for pclass,data in list(titanic.groupby('pclass')['age'])]"
83+
],
84+
"language": "python",
85+
"metadata": {},
86+
"outputs": [],
87+
"prompt_number": 5
88+
},
89+
{
90+
"cell_type": "code",
91+
"collapsed": false,
92+
"input": [
93+
"ply = plotly.plotly(reg['un'], reg['api_key'])\n",
94+
"ply.iplot(age_by_class)"
95+
],
96+
"language": "python",
97+
"metadata": {},
98+
"outputs": [
99+
{
100+
"output_type": "stream",
101+
"stream": "stdout",
102+
"text": [
103+
"\n",
104+
"\n",
105+
"\n"
106+
]
107+
},
108+
{
109+
"html": [
110+
"<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~pandas_and_plotly_demo/1/600/600\" width=\"650\"></iframe>"
111+
],
112+
"metadata": {},
113+
"output_type": "pyout",
114+
"prompt_number": 9,
115+
"text": [
116+
"<IPython.core.display.HTML at 0x10ed83f90>"
117+
]
118+
}
119+
],
120+
"prompt_number": 9
121+
}
122+
],
123+
"metadata": {}
124+
}
125+
]
126+
}

0 commit comments

Comments
 (0)