{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "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", "collapsed": false, "input": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "from statsmodels.graphics.factorplots import interaction_plot" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "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))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "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)" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }