{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Advanced plotting\n", "\n", "This tutorial will go over more advanced plotting functionality. Before reading this, you should take a look at the basic analysis and plotting tutorial. First, we'll load in some example data. This dataset is an `egg` comprised of 30 subjects, who each performed 8 study/test blocks of 16 words each." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import quail\n", "%matplotlib inline\n", "egg = quail.load_example_data()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Accuracy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "accuracy = egg.analyze('accuracy')\n", "accuracy.get_data().head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, the `analyze` function will perform an analysis on each list separately, so when you plot the result, it will plot a separate bar for each list, averaged over all subjects:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = accuracy.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can plot the accuracy for each subject by setting `plot_type='subject'`, and we can change the name of the subject grouping variable by setting the `subjname` kwarg:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = accuracy.plot(plot_type='subject', subjname='Subject Number')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Furthermore, we can add a title using the `title` kwarg, and change the y axis limits using `ylim`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = accuracy.plot(plot_type='subject', subjname='Subject Number',\n", " title='Accuracy by Subject', ylim=[0,1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also group the subjects. This is useful in cases where you might want to compare analysis results across multiple experiments. To do this we will reanalyze the data, averaging over lists within a subject, and then use the `subjgroup` kwarg to group the subjects into two sets:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "accuracy = egg.analyze('accuracy', listgroup=['average']*8)\n", "accuracy.get_data().head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = accuracy.plot(subjgroup=['Experiment 1']*15+['Experiment 2']*15)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Oops, what happened there? By default, the `plot` function looks to the List column of the df to group the data. To group according to subject group, we must tell the plot function to plot by `subjgroup`. This can be achieved by setting `plot_type='subject'`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = accuracy.plot(subjgroup=['Experiment 1']*15+['Experiment 2']*15, plot_type='subject')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you also have a list grouping (such as first 4 lists / second 4 lists), you can plot the interaction by setting `plot_type='split'`. This will create a plot with respect to both the `subjgroup` and `listgroup`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "accuracy = egg.analyze('accuracy', listgroup=['First 4 Lists']*4+['Second 4 Lists']*4)\n", "ax = accuracy.plot(subjgroup=['Experiment 1']*15+['Experiment 2']*15, plot_type='split')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Memory fingerprints" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Memory Fingerprint plotting works exactly the same as the the accuracy plots, with the except that `plot_type='split'` only works for the accuracy plots, and the default `plot_style` is a violinplot, instead of a barplot." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fingerprint = egg.analyze('fingerprint', listgroup=['First 4 Lists']*4+['Second 4 Lists']*4)\n", "ax = fingerprint.plot(subjgroup=['Experiment 1']*15+['Experiment 2']*15, plot_type='subject')\n", "ax = fingerprint.plot(subjgroup=['Experiment 1']*15+['Experiment 2']*15, plot_type='list')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other analyses\n", "\n", "Like the plots above, spc, pfr and lagcrp plots can all be plotted according to `listgroup` or `subjgroup` by setting the `plot_type` kwarg." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot by list grouping" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "listgroup = ['First 4 Lists']*4+['Second 4 Lists']*4\n", "plot_type = 'list'\n", "\n", "spc = egg.analyze('spc', listgroup=listgroup)\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "ax = spc.plot(plot_type=plot_type, ylim=[0, 1])\n", "\n", "pfr = egg.analyze('pfr', listgroup=listgroup)\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "ax = pfr.plot(plot_type=plot_type)\n", "\n", "lagcrp = egg.analyze('lagcrp', listgroup=listgroup)\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "ax = lagcrp.plot(plot_type=plot_type)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot by subject grouping" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "listgroup=['average']*8\n", "subjgroup = ['Experiment 1']*15+['Experiment 2']*15\n", "plot_type = 'subject'\n", "\n", "spc = egg.analyze('spc', listgroup=listgroup)\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "ax = spc.plot(subjgroup=subjgroup, plot_type=plot_type, ylim=[0,1])\n", "\n", "pfr = egg.analyze('pfr', listgroup=listgroup)\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "ax = pfr.plot(subjgroup=subjgroup, plot_type=plot_type)\n", "\n", "lagcrp = egg.analyze('lagcrp', listgroup=listgroup)\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "import matplotlib.pyplot as plt\n", "plt.figure()\n", "ax = lagcrp.plot(subjgroup=subjgroup, plot_type=plot_type)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }