Created
May 9, 2014 08:33
-
-
Save msund/4cb96ed6198f24e59592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "Untitled0" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "%matplotlib inline\nimport matplotlib.pyplot as plt # side-stepping mpl backend\nimport matplotlib.gridspec as gridspec # subplots\nimport numpy as np", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import plotly.plotly as py\nimport plotly.tools as tls\nfrom plotly.graph_objs import *\n# py.sign_in(\"IPython.Demo\", \"1fw3zw2o13\")", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 22 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import plotly\nplotly.__version__", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 23, | |
"text": "'1.0.0'" | |
} | |
], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from ggplot import *", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom ggplot import *", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "a = ggplot(meat, aes('date','beef * 2000')) + \\\n geom_line(color='coral') + \\\n scale_x_date(breaks=date_breaks('36 months'), labels='%Y') + \\\n scale_y_continuous(labels='millions')", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 32 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "fig = a.draw() \npy.iplot_mpl(fig, strip_style=True)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~PythonAPI/336\" height=\"525\" width=\"100%\"></iframe>", | |
"metadata": {}, | |
"output_type": "display_data", | |
"text": "<IPython.core.display.HTML at 0x10fadd4d0>" | |
} | |
], | |
"prompt_number": 33 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "b = ggplot(diamonds, aes(x='price', fill='cut')) +\\\n geom_density(alpha=0.25) +\\\n facet_wrap(\"clarity\")", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 37 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom ggplot import *", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 41 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "meat = meat.dropna(thresh=800, axis=1) # drop columns that have fewer than 800 observations\nts = meat.set_index(['date'])", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 42 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ts.groupby(ts.index.year).sum().head(10)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>beef</th>\n <th>veal</th>\n <th>pork</th>\n <th>lamb_and_mutton</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>1944</th>\n <td> 8801</td>\n <td> 1629</td>\n <td> 11502</td>\n <td> 1001</td>\n </tr>\n <tr>\n <th>1945</th>\n <td> 9936</td>\n <td> 1552</td>\n <td> 8843</td>\n <td> 1030</td>\n </tr>\n <tr>\n <th>1946</th>\n <td> 9010</td>\n <td> 1329</td>\n <td> 9220</td>\n <td> 946</td>\n </tr>\n <tr>\n <th>1947</th>\n <td> 10096</td>\n <td> 1493</td>\n <td> 8811</td>\n <td> 779</td>\n </tr>\n <tr>\n <th>1948</th>\n <td> 8766</td>\n <td> 1323</td>\n <td> 8486</td>\n <td> 728</td>\n </tr>\n <tr>\n <th>1949</th>\n <td> 9142</td>\n <td> 1240</td>\n <td> 8875</td>\n <td> 587</td>\n </tr>\n <tr>\n <th>1950</th>\n <td> 9248</td>\n <td> 1137</td>\n <td> 9397</td>\n <td> 581</td>\n </tr>\n <tr>\n <th>1951</th>\n <td> 8549</td>\n <td> 972</td>\n <td> 10190</td>\n <td> 508</td>\n </tr>\n <tr>\n <th>1952</th>\n <td> 9337</td>\n <td> 1080</td>\n <td> 10321</td>\n <td> 635</td>\n </tr>\n <tr>\n <th>1953</th>\n <td> 12055</td>\n <td> 1451</td>\n <td> 8971</td>\n <td> 715</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 43, | |
"text": " beef veal pork lamb_and_mutton\n1944 8801 1629 11502 1001\n1945 9936 1552 8843 1030\n1946 9010 1329 9220 946\n1947 10096 1493 8811 779\n1948 8766 1323 8486 728\n1949 9142 1240 8875 587\n1950 9248 1137 9397 581\n1951 8549 972 10190 508\n1952 9337 1080 10321 635\n1953 12055 1451 8971 715" | |
} | |
], | |
"prompt_number": 43 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from ggplot import meat\nmeat_lng = pd.melt(meat, id_vars=['date'])\nc = ggplot(aes(x='date', y='value', colour='variable'), data=meat_lng) + geom_line()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 49 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "fig = c.draw() \npy.iplot_mpl(fig, strip_style = True)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~PythonAPI/341\" height=\"525\" width=\"100%\"></iframe>", | |
"metadata": {}, | |
"output_type": "display_data", | |
"text": "<IPython.core.display.HTML at 0x10fb1a810>" | |
} | |
], | |
"prompt_number": 52 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from ggplot import *\n\nd = ggplot(aes(x='date', y='beef'), data=meat) +\\\n geom_line() +\\\n stat_smooth(colour='blue', span=0.2)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 53 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "fig = d.draw() \npy.iplot_mpl(fig, strip_style = True)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~PythonAPI/342\" height=\"525\" width=\"100%\"></iframe>", | |
"metadata": {}, | |
"output_type": "display_data", | |
"text": "<IPython.core.display.HTML at 0x10f61ad10>" | |
} | |
], | |
"prompt_number": 54 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment