{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot Interaction of Categorical Factors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we will vizualize the interaction between categorical factors. First, we will create some categorical data are initialized. Then plotted using the interaction_plot function which internally recodes the x-factor categories to ingegers." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "from statsmodels.graphics.factorplots import interaction_plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "np.random.seed(12345)\n", "weight = pd.Series(np.repeat(['low', 'hi', 'low', 'hi'], 15), name='weight')\n", "nutrition = pd.Series(np.repeat(['lo_carb', 'hi_carb'], 30), name='nutrition')\n", "days = np.log(np.random.randint(1, 30, size=60))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(6, 6))\n", "fig = interaction_plot(x=weight, trace=nutrition, response=days, \n", " colors=['red', 'blue'], markers=['D', '^'], ms=10, ax=ax)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }