Created
November 7, 2013 13:50
-
-
Save chriswl/7354868 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": "" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# import sys\n", | |
| "# # sys.path.append('/usr/lib/python2.7/dist-packages/gtk-2.0/')\n", | |
| "# sys.path.append('/usr/lib/python2.7/dist-packages/')\n", | |
| "# import cairo" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "# print(sys.path)\n", | |
| "\n", | |
| "# import matplotlib\n", | |
| "# matplotlib.use('GTK3Agg')\n", | |
| "# %pylab --no-import-all\n", | |
| "\n", | |
| "# import scipy\n", | |
| "from ggplot import *\n", | |
| "\n", | |
| "# matplotlib.matplotlib_fname()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "meat" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "a = aes(x='index')\n", | |
| "a.DEFAULT_ARGS" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "df = pd.DataFrame({\n", | |
| " \"x\": np.arange(0, 100),\n", | |
| " \"y\": np.arange(0, 100),\n", | |
| " \"z\": np.arange(0, 100)\n", | |
| "})\n", | |
| "\n", | |
| "df['cat'] = np.where(df.x*2 > 50, 'blah', 'blue')\n", | |
| "df['cat'] = np.where(df.y > 50, 'hello', df.cat)\n", | |
| "df['cat2'] = np.where(df.y < 15, 'one', 'two')\n", | |
| "df['y'] = np.sin(df.y)\n", | |
| "\n", | |
| "gg = ggplot(aes(x=\"x\", y=\"z\", color=\"cat\", alpha=0.2), data=df)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "gg" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "gg = ggplot(aes(x=\"x\", color=\"c\"), data=pd.DataFrame({\"x\": np.random.normal(0, 1, 10000), \"c\": [\"blue\" if i%2==0 else \"red\" for i in range(10000)]}))\n", | |
| "gg" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "#print gg + geom_density() + xlab(\"x label\") + ylab(\"y label\")\n", | |
| "gg = ggplot(aes(x=\"x\", y=\"y\", shape=\"cat2\", color=\"cat\"), data=df)\n", | |
| "#print gg + geom_point() + facet_wrap(x=\"cat\", y=\"cat2\")\n", | |
| "#print gg + geom_point() + facet_wrap(y=\"cat2\") + ggtitle(\"My Single Facet\")\n", | |
| "#print gg + stat_smooth(color=\"blue\") + ggtitle(\"My Smoothed Chart\")\n", | |
| "#print gg + geom_histogram() + ggtitle(\"My Histogram\")\n", | |
| "#print gg + geom_point() + geom_vline(x=50, ymin=-10, ymax=10)\n", | |
| "#print gg + geom_point() + geom_hline(y=50, xmin=-10, xmax=10)\n", | |
| "df['z'] = df['y'] + 100\n", | |
| "gg = ggplot(aes(x='x', ymax='y', ymin='z'), data=df)\n", | |
| "#print gg + geom_bar() + facet_wrap(x=\"cat2\")\n", | |
| "#print gg + geom_area() + facet_wrap(x=\"cat2\")\n", | |
| "gg = ggplot(aes(x='x', ymax='y', ymin='z', color=\"cat2\"), data=df)\n", | |
| "#print gg + geom_area()\n", | |
| "df['x'] = np.random.randint(0, 10, 100)\n", | |
| "df['y'] = np.random.randint(0, 10, 100)\n", | |
| "gg = ggplot(aes(x='x', y='y', shape='cat', color='cat2'), data=df)\n", | |
| "#print df.head()\n", | |
| "#print gg + geom_point()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "meat_lng = pd.melt(meat[['date', 'beef', 'pork', 'broilers']], id_vars='date')\n", | |
| "ggplot(aes(x='date', y='value', colour='variable'), data=meat_lng) + \\\n", | |
| " geom_point() + \\\n", | |
| " stat_smooth(color='red')" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "## Meat" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "meat_lng = pd.melt(meat, id_vars=['date'])\n", | |
| "\n", | |
| "p = ggplot(aes(x='date', y='value'), data=meat_lng)\n", | |
| "print(p) " | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "print p + geom_point() + \\\n", | |
| " stat_smooth(colour=\"red\") + \\\n", | |
| " facet_wrap(\"variable\")" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "print p + geom_histogram()+ facet_wrap()\n", | |
| "p = ggplot(diamonds, aes(x='price'))" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "p = p + geom_density() + \\\n", | |
| " facet_grid(\"cut\", \"clarity\")\n", | |
| "print(p)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "p = ggplot(diamonds, aes(x='carat', y='price'))\n", | |
| "print(p + geom_point(alpha=0.25) + \\\n", | |
| " facet_grid(\"cut\", \"clarity\"))" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment