data-science-ipython-notebooks/matplotlib/matplotlib.ipynb

587 lines
279 KiB
Plaintext
Raw Normal View History

{
"metadata": {
"name": "",
"signature": "sha256:b9b2f9479b5476332be91a56ede4d0d4db39f54e70ab41f0b75e3698754f5d98"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Setting Global Parameters\n",
"* Basic Plots\n",
"* Histograms\n",
"* Two Histograms on the Same Plot\n",
"* Scatter Plots\n",
"* Applying Matplotlib Visualizations to Kaggle: Titanic\n",
"* Bar Plots, Histograms, subplot2grid\n",
"* Normalized Plots\n",
"* Scatter Plots, subplots\n",
"* Kernel Density Estimation Plots"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import pandas as pd\n",
"import numpy as np\n",
"import pylab as plt\n",
"import seaborn\n",
"\n",
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting Global Parameters"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Set the global default size of matplotlib figures\n",
"plt.rc('figure', figsize=(10, 5))\n",
"\n",
"# Set seaborn aesthetic parameters to defaults\n",
"seaborn.set()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic Plots"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = np.linspace(0, 2, 10)\n",
"\n",
"plt.plot(x, x, 'o-', label='linear')\n",
"plt.plot(x, x ** 2, 'x-', label='quadratic')\n",
"\n",
"plt.legend(loc='best')\n",
"plt.title('Linear vs Quadratic progression')\n",
"plt.xlabel('Input')\n",
"plt.ylabel('Output');\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUg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G7veZdvhnUxM\nHM/ZqSd397eCXURExEHZhZt5d8+HJPYawIL0b3Cyd38p2EVERBxSVFPMU7nPEhEazu3jF9ArvNdJ\nL1PBLiIi4oB6VwOPbVxOTWMt15grGRI3qFOW25W3u3UL963IIne3txdO+rB4fnjt5JNa3ltvvU5O\nziZCQ0P5/vd/0hkliohIEHh+6yvsqzzIqQNnMGvgtE5bblDtsd+3Iouc3aV48A6InLO7lB88+Bl7\nDnW8eUNISAixsXEKdRERabMvDq7h87w1pMYO4uoxl3XqsnvUHvtz/9zOmi2tDxBXXF77tWmlFXX8\n+sk1xMdFt/ia6WOTuPqsUcddb17eQe644xaWLFnGzTdfy+TJU9m+fRshISH8/vd/pHfvWB5++K9k\nZ6/H7XZzzTXXM3fuOWRlfcUTTzyG2+2mpqaG//7v3xAeHs5PfvI9+vbtx6xZs7n++pva9yGIiEi3\ntq/iIM9ufZle4b24fcICIsIiOnX5PSrYnXTkKsbq6mrOOecC/vM/f8SvfnUvX375OTExvcnLO8hD\nDz1GXV0dd955C9Onn8Lu3bu4995fk5CQwPLly/jww/c577wLKSkpYenSvxMers0jItKTVDfU8Nim\n5TS4G7lt/I0k9BrQ6evoUclx9Vmjjrt3feRQfFPxcVHcPT+ToSkd6/DTkjFjDABJScnU19eTn38I\na7fwH/9xBwAul4u8vIMkJCRw//1/ICYmhsLCAjIzJwEwcOAghbqISA/j8Xh4Ovc5imqKOW/oXCYk\nZPhlPUGVHj+8djI/ePAzSivq
"text": [
"<matplotlib.figure.Figure at 0x10bbb9910>"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Histograms"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Gaussian, mean 1, stddev .5, 1000 elements\n",
"samples = np.random.normal(loc=1.0, scale=0.5, size=1000)\n",
"print(samples.shape)\n",
"print(samples.dtype)\n",
"print(samples[:30])\n",
"plt.hist(samples, bins=50);\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(1000,)\n",
"float64\n",
"[ 1.44418744 0.46400374 1.25345292 1.97078609 0.80932915 0.09078554\n",
" 0.66967121 0.15271056 0.57636656 0.84077082 1.35157266 0.29905241\n",
" 1.38532784 1.80721741 0.4306797 0.43750271 0.6245115 1.06267641\n",
" 1.51031708 1.38542507 1.2802048 1.48447563 1.36070319 -0.0184091\n",
" 0.42067395 0.93246141 1.75653823 1.21452101 1.41877116 1.21999727]\n"
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAeQAAAFVCAYAAAA+OJwpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAF0ZJREFUeJzt3XFs3Gd9x/G3S+NSz8Y0kcNGagUtS78qmmC0aGwMNelW\nqmWjLUOb0GAdrdjGRjVlDJXRwCptYitaSKVU66otlIUxiXXtSpeqaunWVU1bsTFYGUQNTyiUxNWq\nxuQcE9cEJ7H3h8/FdXz3O5995+fu935JVX33/O5+3ye/8338u+d3z9MzMzODJElaXeesdgGSJMlA\nliQpCwayJEkZMJAlScqAgSxJUgYMZEmSMnBu0QYR8T7guurN84E3Am8DdgPTwAHghpSS35+SJKlJ\nPUv5HnJE/DXwNeAqYFdKaX9E3AF8MaV0X4tqlCSp6zX8kXVEvBl4fUrp08ClKaX91aYHgStaUZwk\nSWWxlDHkHcCfVX/umXf/BDC4YhVJklRChWPIABHxauCilNJj1bum5zUPAMfrPX5mZmamp6en3iaS\nJHWTJYdeQ4EMXAY8Mu/2UxGxpRrQ2xa0nV1VTw+joyeWWlvXGBoaKG3/y9x3sP/2v7z9L3PfYbb/\nS9VoIF8EfHve7Q8DeyKiF3gauGfJe5YkSS9pKJBTSp9acPtbwNZWFCRJUhk5MYgkSRkwkCVJyoCB\nLElSBgxkSZIyYCBLkpQBA1mSpAwYyJIkZcBAliQpAwayJEkZMJAlScqAgSxJUgYMZEmSMtDoak+S\nlLWpq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XXvPd/vqvp8x9h+b+GCn8yDoiro2Im6o3fwCcAb4SEVuq920D9i/6YEmS1JBG\nzpDvAfZGxGPAGmA78E1gT0T0
"text": [
"<matplotlib.figure.Figure at 0x10bbccf50>"
]
}
],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Two Histograms on the Same Plot"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"samples_1 = np.random.normal(loc=1, scale=.5, size=10000)\n",
"samples_2 = np.random.standard_t(df=10, size=10000)\n",
"bins = np.linspace(-3, 3, 50)\n",
"\n",
"# Set an alpha and use the same bins since we are plotting two hists\n",
"plt.hist(samples_1, bins=bins, alpha=0.5, label='samples 1')\n",
"plt.hist(samples_2, bins=bins, alpha=0.5, label='samples 2')\n",
"plt.legend(loc='upper left');\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAeoAAAFVCAYAAAAg8ayaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XuU5Gdd5/F3d/Vl+lLdk+7pcJEAIvIQl0GusgZMwnEM\nBuMSNCorsiFggjHcNGuQkYOGTRiUi0uURUjQgLAuaw664ByIIWIShoUIRAgQnzUcArlnprv6VlXT\n1V1V+0f3hMmk69Ld1dVPdb9f58xJV9V3fvX0bzr9qd/zey5d1WoVSZKUpu6tboAkSarNoJYkKWEG\ntSRJCTOoJUlKmEEtSVLCDGpJkhLW06gghPAC4F0xxheHEJ4FXAWUgQXgv8QYHwohXAhcBCwBV8QY\nD4YQBoCPAxPAHHB+jPHIZn0jkiRtR3WvqEMIlwFXA/0rT/134PUxxhcDnwLeEkJ4DPAG4DTgJcCB\nEEIfcDHwjRjj6cDHgLdtzrcgSdL21ajr+07gl4CulceviDF+c+XrXqAI/BRwKMa4GGOcXfk7zwRe\nCHxupfZzwL5WNlySpJ2gblDHGD/Fcnf2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ig1rStjAzM811n7+dweGRmjVHHriH4dE9ZGuXtFSxMM/BQ5OM7Tm5Zk1h\nfpbz9u1lbGy8PY1SxzGoJW0bg8MjDGd313w9Pz/TxtYsGxyq3yapEe9RS5KUMINakqSEGdSSJCXM\noJYkKWEGtSRJCTOoJUlK2JqnZ4UQuoFrgKcBFeBCoAxcu/L4W8AlMcZqCOFC4CJgCbgixniwRe2W\nJGlHWM8V9VnAUIzxRcA7gHcC
"text": [
"<matplotlib.figure.Figure at 0x10bfb2390>"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scatter Plots"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"plt.scatter(samples_1, samples_2, alpha=0.1);\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAFVCAYAAAA30zxTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3VuMJPme2PVvRGbc836tqr73zJmcs2d2WR8sI1YI1lrL\nsiUsC14REi8IyTzsAwLktWQtCASSpX0CIWQE5hnLQiC00spgmdvDrvccLzNnZ3J6pm91zfs1rpkZ\nwUNkVld1V3dXV1d3dXX/PtJoqrMyMyIjo+IX////9//9lSRJEEIIIcT7pV71DgghhBCfIgnAQggh\nxBWQACyEEEJcAQnAQgghxBWQACyEEEJcAQnAQgghxBXInudJrVbrXwL+y3a7/ZdbrdbnwD8AYuAb\n4N9vt9syl0kIIYR4A69tAbdarf8I+PuAsX7oD4Dfa7fb/yqgAH/z3e2eEEII8XE6Txf0D8C/SRps\nAX7ebrf/z/XPfwj8lXexY0IIIcTH7LUBuN1u/yNgeeIh5cTPc6B42TslhBBCfOzONQb8nPjEz3lg\n/LoXJEmSKIryuqcJIYQQH4vXBr2LBOBftlqtf63dbv9T4K8D//tr90JR6PVmF9jUp6Vez8txOgc5\nTucnx+p85Didnxyr86nX8699zpsE4E2m838A/P1Wq6UDfw78wzffNSGEEOLTdq4A3G63HwO/tf75\nAfDb726XhBBCiI+fFOIQQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIK\nSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGE\nEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAE\nYCGEEOIKSAAWQgghroAEYCGEEOIKSAAWQgghroAEYCGEEOIKZC/yolarpQL/HfAFEAP/brvdbl/m\njgkhhBAfs4u2gP8q4LTb7X8F+E+B//zydkkIIYT4+F00APtAsdVqKUARiC5vl4QQQoiP34W6oIH/\nBzCB74Aq8DcubY+EEEKIT4CSJMkbv6jVav0eaRf032m1WjeB/wP4qt1uv6wl/OYbEUIIIa4v5XVP\nuGgL2AGm659HgAZkXvWCXm92wU19Our1vBync5DjdH5vcqxcNwTAcYx3uUsfJDmnzk+O1fnU6/nX\nPueiAfjvAf9Dq9X6v0iD799ut9v+Bd9LCHHFOh2PJHEAmM9dmk37ivdIiI/fhQJwu90eA//GJe+L\nEOIKuG54HHwBksTBdYNPsiUsxPskhTiEEEKIKyABWIhPnOMYKIp7/G9FcaX1K8R7cNExYCHER6TZ\ntHHdAADHkfFfId4HCcBCCODTzH4W4ipJF7QQQghxBSQACyGEEFdAArAQQghxBSQACyGEEFdAArAQ\nQghxBSQACyGEEFdAArAQQghxBSQACyGEEFdAArAQQghxBSQACyGEEFdAArAQQghxBSQACyGEEFdA\nArAQQghxBSQACyGEEFdAArAQQghxBSQACyGEEFdAArAQQghxBSQACyGEEFdAArAQQghxBSQACyGE\nEFdAArAQQghxBSQACyGEEFcge9EXtlqtvw38DUAD/qt2u/0/XtpeCSGEEB+5C7WAW63WbwP/crvd\n/i3gt4H7l7hPQgghxEfvoi3gvwp83Wq1/megAPyHl7dLQgghxMfv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SB/fBJO3DTbnaaE9Hxg7HY9uVyVJSiiK\nS6PhvSTYToDT82tf5mXH5OTn+OqrKt3uGOA4+J61f5fhZS1ey6rgeSNsu7zej5hcTlnvd/zS7vAP\nefxfiJeRACw+KucNmGn37Ygk
"text": [
"<matplotlib.figure.Figure at 0x10c222f90>"
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Applying Matplotlib Visualizations to Kaggle: Titanic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Prepare the titanic data to plot:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"df_train = pd.read_csv('../data/titanic/train.csv')\n",
"\n",
"def clean_data(df):\n",
" \n",
" # Get the unique values of Sex\n",
" sexes = sort(df['Sex'].unique())\n",
" \n",
" # Generate a mapping of Sex from a string to a number representation \n",
" genders_mapping = dict(zip(sexes, range(0, len(sexes) + 1)))\n",
"\n",
" # Transform Sex from a string to a number representation\n",
" df['Sex_Val'] = df['Sex'].map(genders_mapping).astype(int)\n",
" \n",
" # Get the unique values of Embarked\n",
" embarked_locs = sort(df['Embarked'].unique())\n",
"\n",
" # Generate a mapping of Embarked from a string to a number representation \n",
" embarked_locs_mapping = dict(zip(embarked_locs, \n",
" range(0, len(embarked_locs) + 1)))\n",
" \n",
" # Transform Embarked from a string to dummy variables\n",
" df = pd.concat([df, pd.get_dummies(df['Embarked'], prefix='Embarked_Val')], axis=1)\n",
" \n",
" # Fill in missing values of Embarked\n",
" # Since the vast majority of passengers embarked in 'S': 3, \n",
" # we assign the missing values in Embarked to 'S':\n",
" if len(df[df['Embarked'].isnull()] > 0):\n",
" df.replace({'Embarked_Val' : \n",
" { embarked_locs_mapping[nan] : embarked_locs_mapping['S'] \n",
" }\n",
" }, \n",
" inplace=True)\n",
" \n",
" # Fill in missing values of Fare with the average Fare\n",
" if len(df[df['Fare'].isnull()] > 0):\n",
" avg_fare = df['Fare'].mean()\n",
" df.replace({ None: avg_fare }, inplace=True)\n",
" \n",
" # To keep Age in tact, make a copy of it called AgeFill \n",
" # that we will use to fill in the missing ages:\n",
" df['AgeFill'] = df['Age']\n",
"\n",
" # Determine the Age typical for each passenger class by Sex_Val. \n",
" # We'll use the median instead of the mean because the Age \n",
" # histogram seems to be right skewed.\n",
" df['AgeFill'] = df['AgeFill'] \\\n",
" .groupby([df['Sex_Val'], df['Pclass']]) \\\n",
" .apply(lambda x: x.fillna(x.median()))\n",
" \n",
" # Define a new feature FamilySize that is the sum of \n",
" # Parch (number of parents or children on board) and \n",
" # SibSp (number of siblings or spouses):\n",
" df['FamilySize'] = df['SibSp'] + df['Parch']\n",
" \n",
" return df\n",
"\n",
"df_train = clean_data(df_train)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bar Plots, Histograms, subplot2grid"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Size of matplotlib figures that contain subplots\n",
"figsize_with_subplots = (10, 10)\n",
"\n",
"# Set up a grid of plots\n",
"fig = plt.figure(figsize=figsize_with_subplots) \n",
"fig_dims = (3, 2)\n",
"\n",
"# Plot death and survival counts\n",
"plt.subplot2grid(fig_dims, (0, 0))\n",
"df_train['Survived'].value_counts().plot(kind='bar', \n",
" title='Death and Survival Counts',\n",
" color='r',\n",
" align='center')\n",
"\n",
"# Plot Pclass counts\n",
"plt.subplot2grid(fig_dims, (0, 1))\n",
"df_train['Pclass'].value_counts().plot(kind='bar', \n",
" title='Passenger Class Counts')\n",
"\n",
"# Plot Sex counts\n",
"plt.subplot2grid(fig_dims, (1, 0))\n",
"df_train['Sex'].value_counts().plot(kind='bar', \n",
" title='Gender Counts')\n",
"plt.xticks(rotation=0)\n",
"\n",
"# Plot Embarked counts\n",
"plt.subplot2grid(fig_dims, (1, 1))\n",
"df_train['Embarked'].value_counts().plot(kind='bar', \n",
" title='Ports of Embarkation Counts')\n",
"\n",
"# Plot the Age histogram\n",
"plt.subplot2grid(fig_dims, (2, 0))\n",
"df_train['Age'].hist()\n",
"plt.title('Age Histogram')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 11,
"text": [
"<matplotlib.text.Text at 0x10bf7ba50>"
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAJZCAYAAACN2rCOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XmcXFWZ8PFfyEpMJ5M4jYzKoCI+4oJCRAUVgiLICOIy\njo4rqODCIDOijkZ0NhBHwHlBGVSiBhX1HRgXlBeBicimiCCOMugDKGJcRqLdZCFItn7/OLehaLq7\nOrlVqa7q3/fzySdVt26fe+pW1+nnnvucc6YNDQ0hSZKkbbNDpysgSZLUzQymJEmSajCYkiRJqsFg\nSpIkqQaDKUmSpBoMpiRJkmqY0ekK9KqIeBTwM+BH1aYdgI3AGZn5uZplXwq8MjMHIuIXwEsz8wd1\nypzgcb8BnJ+Z547y2ruBvwamAdOBbwJLM3Nji459EXBCZv50G352OfDjzDx9lNceAZwM7A1sAf4I\nfDAzL6xX4zHr8gHgh+0qX2qnUdo1KN/5MzLzMx2p1HbQrJ2IiC3An2bmQBvrMAd4H/BC7m9nP5+Z\nH27T8V4IPD0z/6Ed5fcae6baa31m7lX9ewrwUuADEfHSmuUeRPkyAQw1PG63oerfA0TEy4EXA8/M\nzKcCTwMeD/xjqw6cmS/clkCqMla9+4HvAJdl5p5V3Y8BzomI5217bcf1XGBmm8qWtofGdm0v4C+A\n0yPiyZ2uWDt0qJ0YWYdpwFeBPko7uxewBHhJRPxzmw67D7CoTWX3HHumtqPM/GXVM/Eu4MsRMQv4\nV2B/ylXGjcDbM3NtRBwGvBeYBewEnJuZH4iI4au/b1VXDgBvjoi9qv0+l5knjjz2OOUtoVxx/Qx4\nEjAbODYzvx0RDwfOBf4MWAn86Rhvbeeq/nOBezPz3oj4G6C/OvZyGnq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},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Get the unique values of Embarked and its maximum\n",
"family_sizes = sort(df_train['FamilySize'].unique())\n",
"family_size_max = max(family_sizes)\n",
"\n",
"df1 = df_train[df_train['Survived'] == 0]['FamilySize']\n",
"df2 = df_train[df_train['Survived'] == 1]['FamilySize']\n",
"plt.hist([df1, df2], \n",
" bins=family_size_max + 1, \n",
" range=(0, family_size_max), \n",
" stacked=True)\n",
"plt.legend(('Died', 'Survived'), loc='best')\n",
"plt.title('Survivors by Family Size')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
"<matplotlib.text.Text at 0x10bf0cb10>"
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAegAAAFeCAYAAABOw4xkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH2lJREFUeJzt3X2cXVV97/HPTJJhIJkQxMOTxoiAS+yVyoN9AEvgCigV\ngtL6cKUiIE8KgV5F1KC5BUEQJEoQKSZiwKvtVao2wguLBiSYXotAqiD6gzQYphRkJE/DgMwkM/1j\n7ySTOJmZTM6Zs3Lm83698sqZvffZ+zcrcL57rb3O3k19fX1IkqS8NNe7AEmS9IcMaEmSMmRAS5KU\nIQNakqQMGdCSJGXIgJYkKUPj612ANNpSSn8GfBbYneIktR24KCIerdL+zwGmRMTnqrG/YR7zN8C7\nI+L+Eb5/AXAM0LHFquMj4pntKq7Y/1LgKOCdwF9FxInb8N63A5cAu1B8Zv0S+EhEPJVSOhE4JiIu\n3N4apdwY0BpTUko7AbdTfKj/e7nsFODOlNKrI2K7bwwQETdt7z5GoA9o2s73z4mIOVWqZzMRcTBA\nSmmb3pdS2gdYABwSEe3lslnAt4AjIuL7wPerWqyUCQNaY80uwK5A24YFEfGNlNIaYHxK6Qjg+oh4\nA0BK6agNP6eU/g74c2Av4BHgL4B3RsSD5bb/CPy4XL87sBC4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z5JPFcPv3vncbN9/8FZ555mlOPfU9zJx5Dt/85q38zd+8a+N+5sz5HIsX/5iZ\nM8/hySd/w5lnnsozzzwNwD33/IjrrruWrq7n+dSnLuaCC87lggvOZfnyZRv3f8YZp/CRj8zk8ccf\nq8nvaUBLknYolcoeXHXVtTz8
"text": [
"<matplotlib.figure.Figure at 0x10bf60910>"
]
}
],
"prompt_number": 12
2015-04-06 20:54:12 +08:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Normalized Plots"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pclass_xt = pd.crosstab(df_train['Pclass'], df_train['Survived'])\n",
"\n",
"# Normalize the cross tab to sum to 1:\n",
"pclass_xt_pct = pclass_xt.div(pclass_xt.sum(1).astype(float), axis=0)\n",
"\n",
"pclass_xt_pct.plot(kind='bar', \n",
" stacked=True, \n",
" title='Survival Rate by Passenger Classes')\n",
"plt.xlabel('Passenger Class')\n",
"plt.ylabel('Survival Rate')\n",
"\n",
"# Plot survival rate by Sex\n",
"females_df = df_train[df_train['Sex'] == 'female']\n",
"females_xt = pd.crosstab(females_df['Pclass'], df_train['Survived'])\n",
"females_xt_pct = females_xt.div(females_xt.sum(1).astype(float), axis=0)\n",
"females_xt_pct.plot(kind='bar', \n",
" stacked=True, \n",
" title='Female Survival Rate by Passenger Class')\n",
"plt.xlabel('Passenger Class')\n",
"plt.ylabel('Survival Rate')\n",
"\n",
"# Plot survival rate by Pclass\n",
"males_df = df_train[df_train['Sex'] == 'male']\n",
"males_xt = pd.crosstab(males_df['Pclass'], df_train['Survived'])\n",
"males_xt_pct = males_xt.div(males_xt.sum(1).astype(float), axis=0)\n",
"males_xt_pct.plot(kind='bar', \n",
" stacked=True, \n",
" title='Male Survival Rate by Passenger Class')\n",
"plt.xlabel('Passenger Class')\n",
"plt.ylabel('Survival Rate')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
2015-04-06 20:54:12 +08:00
"text": [
"<matplotlib.text.Text at 0x10d1a4a90>"
2015-04-06 20:54:12 +08:00
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFpCAYAAAC1YKAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmcXXV9//HXTDJBsgAJBpUlgIAfqRpFkCUoS5GqZTFo\n1SLKJohYob+CtqACgrW4BQpYZDMCFbVgxSpIrGURjYBGAgjiBwkqbVgyMmOWCQlDMr8/zhm4DLPc\nSXJz50xez8djHtx7zrnf8zmZw7zv93u2lp6eHiRJUnW0NrsASZI0PIa3JEkVY3hLklQxhrckSRVj\neEuSVDGGtyRJFTO22QVI9YiIPYF/ATan+NL5v8DHM/M366j9E4DNMvMLa/DZ/YCLMvN1/cxbDdwP\nrAJ6gPHAEuDEzPzVEO0eB7Rl5leHUcvRwPsy8x11b8ALP78fcBPw27LeFuBZ4OzMvGFN2qyCiNgZ\n+GdgR4rt/jPwqcycGxHbAb/OzElNLFF6AcNbI15EbATcALw1M+8ppx0B3BQR22XmWt+sIDMvXds2\nBrFfZnb0vomIU4GLgBlDfO7NwK8bWNdAHs7MXXrfRMR0YG75b/1UE+ppqIgI4H+AozPzx+W0vwRu\niIgZwNPNrE/qj+GtKhgPbAo81/PJzGsiYjEwNiL2pqbnW9sTjojPAHsBL6foAb8FOKy31xsR3wZu\nK+dvDnwfmJWZ08v5mwGPANuXnz0dGAdsAVyVmWfWUX9L74uIGAtsCzxVvn8ZcGnZ3suBPwLvpQju\nQ4C3RsTyzPxqRHwKeBfFyMMfgI9m5uP9rO9lEfFDYKuyveOBjcrt3zozl0REC5DAuzNz0C8ImXlf\nRCwHti3rf1G9mdkeEScCJwDPACuAEzLzwUGmb0XxJWYa0AZ8OzPPLXu6NwM3AnsAUyh6wddGxHjg\nknL6n4EHgZ7MPGaI9n4K/AbYDtgnM5+s2cTTgNm9wV1u8y0R8bdlvc8Z6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jrAF6/1Fd49ABFxODAxMy+PiFMobjzRCnwt+3/AgiRJ6qPh4Z2Zf6B89GFmfqtm+g0UN72Q\nJEnD4O1RJUmqGMNbkqSKMbwlSaoYw1uSpIoxvCVJqhjDW5I06j15+x9YcOV8Hp59Nwu+fjfLH1vz\n67kvvHAWTz75xBp//rzzvsD8+b9a48+Dz/OWJI1yKxZ1sSSfYqfjdwXg6SeW8uh3HyQ+uvsatXfy\nyaeuVT0tLf3eNG1Y7HlLkka1MS8ZS/fiFTx192N0L1nJxi+fxE4f3o2HZ9/Nyj8Vd+9c8kA711//\nHZ544nGOPPJ9nHTSCXzzm1fzgQ+857l2zjvvC9x++22cdNIJPProHzjuuCN54oni/mK33vo/XHDB\nLLq6lvHpT/8jJ5/8EU4++SM88sjDAHzve9/h2GOP4JRTTuJ3v3torbfJ8JYkjWptm2zEdkdMZ/mj\ni/nd5fP47YV3siT/9MKFajrDHR0dnH/+v/H+9x/JDjvsyL33zueZZ55h/vxfsffeb3luuYMPPpQ5\nc24E4KabbuDQQw/jqqtms9tuu3PhhZfwiU98ki9/+fN0dnZy7bXf4rLLruLLX76AlpaWte59O2wu\nSRrVVnYsZ8xGY9lm5s4ALH9sCY9cfS9tkzZ6fqGe51++4hVbMnZsEY+HHHIYN910A0899RRvfvO+\njBnT+4CsFg488O189KPHc/DBM+nq6mL77V/JI488zPz587j55h8DsHTpEhYu/F+23Xb759p83ete\nT09PzQrXgOEtSRrVVjzRxVPzFrL9EdNpGdPKRlPGM2bjsYwd30b30pVs9NLxrGxfDpsXy7e2Pj8o\nvdtuu3PxxRfS3t7Oqaf+0wvanTBhIhGv5sILZ3HQQYcCsO222/PqV+/MgQe+nfb2Rfz4x3PYeutp\n/P73j7By5QrGjduIBx98gD33
2015-04-06 20:54:12 +08:00
"text": [
"<matplotlib.figure.Figure at 0x10c536d90>"
2015-04-06 20:54:12 +08:00
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAA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ZfTw6U9FCcDPV/z\nfgGwaiNrkSRppGjWTVqep7iNZZeJwLy+PvDyy690jhkzoCtlGu6hhx5i5vmHMX7KxP4XXoEtalvA\nufuewtve9rZmlzKs2Z/qZ5+qj32qfsO4T/V42WGzwvtPFNeRTgIWUewy7/OpR/PmLe5rdlO0ty9k\n/JSJTFxrtWaXMuy1ty+krW1Bs8sY1uxPA2Of6p99amCGY5+a0ssXr6EK706AiNgTmJCZ55S3fbyO\nYtf9DzLzqSGqRZKkSmt4eJcPc5hRvv5xzfSfU9zkQJIkDYB3WJMkqWIMb0mSKsbwliSpYgxvSZIq\nxvCWJKliDG9J0oj3zM2P8cj59zDnvLt55Id3s/jJZb+e+/TTT+aZZ55e5s+fcso3ueeeu5b589C8\nm7RIkjQkXnx2EfPzOTY5YEsAXnh6AU9c/iBx8FbL1N6hhx6+XPW0tPR407QBceQtSRrRRr9pDB3P\nv8hzdz9Jx/wlrPzWiWzy+enMOe9ulvy1uHvn/AfauOKKy3j66afYe+9PccghB3LxxRfymc988tV2\nTjnlm9x8840ccsiBPPHEY8ycuTdPP13cX+yGG37NaaedzKJFCznmmH/j0EO/wKGHfoFHH50DwJVX\nXsb+++/FYYcdwsMPP7Tc22R4S5JGtNZVVmL9vaax+Innefic2fzp9NuZn399/UI1g+H29nZOPfV7\nfPrTe7PRRhtz77338NJLL3HPPXex7bbbvbrcLrvsxrXXXg3ANdf8nN1224MLLjiP6dO34vTTZ3Hk\nkV/mO985iXnz5nHJJT/m7LMv
2015-04-06 20:54:12 +08:00
"text": [
"<matplotlib.figure.Figure at 0x10c288f10>"
2015-04-06 20:54:12 +08:00
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFxCAYAAABa5SD+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XecXXWd//HXpCFkAgQMKBqq8IFFUTAqgoAssjZAwMIi\nSDOIDd1F3UVFEFx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x9anCG\n4z41qY8vXisqvLsAImJfoDMzz6hvCXk51dD99zLzkRVUiyRJRWt5eNcPetiufv2ThukXU90AQZIk\nDYJ3WJMkqTCGtyRJhTG8JUkqjOEtSVJhDG9JkgrTruu8W+aHPzybW265iSVLljBq1Cg+8Yl/IWLz\n5Wrr5JNPZJ999mPddV+2XJ//68XJmluuQ+dGE5fr85Ik9WZEhff999/Hddddw3e/exYA99wzna9+\n9cucffa5y9Xepz71mRdXUEevN8aRJOlFGVHD5p2dnTz22GNcfPEvmDXrcTbddDPOOOMcPvnJj/Dg\ngw8AcMEFP+Oss07n0Ucf4YAD9uHwww/j3HN/wP77v/+5dqZN+zrXXHMVhx9+GA8++BemTj2ARx+t\n7iFz5ZW/4ZvfPJGFCxdwyikn8fCF07n3+7fy1GMLAHjiDzOZ/t2buO8Hf+TpR4bXnXokSSPDiArv\nSZPW4fjjT+TOO2/nox89hP32ex/XXnsNHS/oAT//evbs2Zx00rf54AcPYJNNXsXtt9/Gs88+y223\n3cL22+/w3HK77bYHl112CQCXXnoxe+yxF+eccxZbbvlq1ttjM165x+bMvChZsvBZnrj+ITb9yBQ2\n2v+11arsfEuShtiIGjafOfOv
2015-04-06 20:54:12 +08:00
"text": [
"<matplotlib.figure.Figure at 0x10ced51d0>"
2015-04-06 20:54:12 +08:00
]
}
],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scatter Plots, subplots"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Set up a grid of plots\n",
"fig, axes = plt.subplots(2, 1, figsize=figsize_with_subplots)\n",
"\n",
"# Histogram of AgeFill segmented by Survived\n",
"df1 = df_train[df_train['Survived'] == 0]['Age']\n",
"df2 = df_train[df_train['Survived'] == 1]['Age']\n",
"max_age = max(df_train['AgeFill'])\n",
"\n",
"axes[1].hist([df1, df2], \n",
" bins=max_age / 10, \n",
" range=(1, max_age), \n",
" stacked=True)\n",
"axes[1].legend(('Died', 'Survived'), loc='best')\n",
"axes[1].set_title('Survivors by Age Groups Histogram')\n",
"axes[1].set_xlabel('Age')\n",
"axes[1].set_ylabel('Count')\n",
"\n",
"# Scatter plot Survived and AgeFill\n",
"axes[0].scatter(df_train['Survived'], df_train['AgeFill'])\n",
"axes[0].set_title('Survivors by Age Plot')\n",
"axes[0].set_xlabel('Survived')\n",
"axes[0].set_ylabel('Age')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 14,
"text": [
"<matplotlib.text.Text at 0x10bf60690>"
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAmgAAAJoCAYAAADS7x1JAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xl8XHW5+PFPkrakQGhRU7YLXPTCV6+KICgUZBEBqSAI\nKiAUKGsBWVQ2BYqXIkrLJqAgIKVlkRZRsAoVEJR6uXUBWQUfQFT6Q4EK3aiE0jS/P86JCZlJm6WZ\nOe183q/XvMg8M3PmmW9CzzPf5Xzr2trakCRJUnHUVzsBSZIkvZ0FmiRJUsFYoEmSJBWMBZokSVLB\nWKBJkiQVjAWaJElSwQyqdgKSVh4ppW2BbwLvJPuCNxs4NSKeWkHHHwsMj4gJK+J4PXzPvwL7R8Tv\n+nGMDwKPAV9b0bmnlCYDuwJzgDZgMPBn4OiImJPnv19E/GEZx/gIcEREHLcic5M0cOxBk9QjKaXV\ngJ8BX4mID0XEB4GbgRkppboV8R4RcXUli7NcG9Df/I8ja4svppQa+p/S27QBl0TElhHx4bzdnwOu\n7PT48rwf+I8VnJekAWQPmqSeWh0YBjS1ByLi5pTSfGBQSml74Iq8gCCltHP7/ZTS/wAjgXWBJ4Ed\ngH0j4uH8uVOBX+WPvxOYDlwcEZvnjw8Hngc2ISs0vgO8g6w4uTgibszf7zLg9TzXnYDrgP8ClgIP\nA2MjolxBc2xK6btAY36861NK1wKvRMRZeQ4HA5+NiP06vzCl1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8SVVx4JTAB2z28T85gkSSoa\nC7QacdFFdwFfp2OI85w8JklSefPmzWPs2G/zhS9cwLx586qdTk1xiFOSJJWYN28eW289hQULvgrA\nXXdN4KGHDmP48OFVzqw22INW
"text": [
"<matplotlib.figure.Figure at 0x10c536250>"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Kernel Density Estimation Plots"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Get the unique values of Pclass:\n",
"passenger_classes = sort(df_train['Pclass'].unique())\n",
"\n",
"for pclass in passenger_classes:\n",
" df_train.AgeFill[df_train.Pclass == pclass].plot(kind='kde')\n",
"plt.title('Age Density Plot by Passenger Class')\n",
"plt.xlabel('Age')\n",
"plt.legend(('1st Class', '2nd Class', '3rd Class'), loc='best')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 15,
2015-04-10 23:29:05 +08:00
"text": [
"<matplotlib.legend.Legend at 0x10d4ad3d0>"
2015-04-10 23:29:05 +08:00
]
},
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAf0AAAFtCAYAAAANqrPLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XecFdX5+PHPbdt7pZdd4NDFCjbEFqKJfk2iKfozif2L\nUZMYTTOaGKNGTbMnGqMxMfGrJjH2QjSoqCgoIAgH2KXD9t27ffeW+f0xd5Zl2XLLzMLuPu/Xy5fs\nnZkzZ3ZhnzntOS7DMBBCCCHE8Oc+2BUQQgghxOCQoC+EEEKMEBL0hRBCiBFCgr4QQggxQkjQF0II\nIUYICfpCCCHECOE92BUQIl5KKR+wHVijtT7DxnK/CdwNlEc+8gA1wA+01h/adZ9u97sCyNFa36GU\nuhTwaa0fjOH6MLAOCAEG4AOe0Fr/Uim1CLhXaz1ngDJuAlZrrZ/r8fki4EGt9YxYnqnb9ZOAMmBt\nt49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Orjvvt/xrW9dxlVXXc7113+bqqpKAM499ywCgaGz\ns7EEfSEOknBHBzX/eAZ3aire/Hz8y96kY/eug10tIYadJ574M3fe+YsBg/OqVR/yySdrDvj8nnt+\nTXHxKO6//2Huu+8hzjrrC9x0k7n78lDLCOtkch4hRD+aVn5AuLWFvM+dRfLESex94F4a311O4Xlf\nOdhVE8IRT72xhQ83Vtla5tHTi/jyKVP6PWfcuPHceutd3HLLTV2f/fOfT/PKKy/idruZPn0m11xz\nLX/962N0dHQwZ85hHH/8iQAEAgHeeectrr/+x13XLly4iHnzjtjvHuXlW7jvvt8RCoXx+xu47rof\nMnv2XG677WZ2795FR0cH5533
"text": [
"<matplotlib.figure.Figure at 0x10c2dae10>"
]
}
],
"prompt_number": 15
}
],
"metadata": {}
}
]
}