<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Errorbarjitter
Introduction
The purpose of this script is to provide modular code for generating errorbarjitter plots using python and pandas. The framework for this code was written in collaboration with Jason Wittenbach (@jwittenbach) of Janelia Research Campus. The idea is based on the matlab errorbarjitter code writtten by David Stern, also of Janelia Research Campus. This version uses free and open source software to achieve the same plot.
As in the original errorbarjitter, this function plots the mean ± SD of one or more samples alongside the raw data.
The raw data are "jittered" and an alpha value adds transparency to aid in separation of individual data points. This form of data presentation invites active analysis of the raw data by the reader.
The following arguments can be passed to errorbarjitter
Step1:  errorbarjitter function
Step2:  Example 1
Step3:  Iris dataset example
In this second example I use the iris dataset, obtained from Anderson[1].
It is simple to use errorbarjitter to plot the each of the metrics by speices as shown below.
Step4:  References
Step5:  Learning Index
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
sns.set_style('darkgrid')
sns.set_context('talk')
Explanation: Errorbarjitter
Introduction
The purpose of this script is to provide modular code for generating errorbarjitter plots using python and pandas. The framework for this code was written in collaboration with Jason Wittenbach (@jwittenbach) of Janelia Research Campus. The idea is based on the matlab errorbarjitter code writtten by David Stern, also of Janelia Research Campus. This version uses free and open source software to achieve the same plot.
As in the original errorbarjitter, this function plots the mean ± SD of one or more samples alongside the raw data.
The raw data are "jittered" and an alpha value adds transparency to aid in separation of individual data points. This form of data presentation invites active analysis of the raw data by the reader.
The following arguments can be passed to errorbarjitter:
1. df -- dataframe to be analyzed
2. groupByCol -- choose the column which contains the groups you would like to analyze by.
3. statsCol -- choose the metric on which you would like to calculate the mean and SD
4. fig -- can set fig = plt.fig() if you add additional information to the plot
5. xlab -- can pass a string argument in quotes for the x label
6. ylab -- can pass a string argument in quotes for the y label
7. rotate -- number of degrees by which to rotate the label on the x-axis, set to default of 0
End of explanation
def errorbarjitter(df, groupByCol, statsCol, fig=None, xlab='group', ylab='units', rotate = 0):
    grouped = df.groupby([groupByCol])
    stats = grouped.aggregate({statsCol:[np.std, np.mean]})
    groups = df[groupByCol].unique()
    means, devs = stats[statsCol]['mean'], stats[statsCol]['std']
    
    plt.figure(figsize=(15,7))
    
    if fig is None:
        fig = plt.figure()
        
    for (i, (m, s)) in enumerate(zip(means, devs)):
        pts = np.array(df[df[groupByCol]==groups[i]][statsCol])
        x = i*np.ones(len(pts)) + 0.2*np.random.rand(len(pts))-0.1
        plt.scatter(x, pts, c='k', alpha=0.5)
        delta = 0.22
        plt.scatter(i+delta, m, edgecolor='k', facecolor='none', linewidth=3, s=25)
        plt.plot([i+delta, i+delta], [m-s, m+s], '-', c=[0, 0, 0], lw=2.0)
    plt.xticks(range(len(groups)), groups, rotation=rotate);
    plt.xlabel(xlab)
    plt.ylabel(ylab)
Explanation: errorbarjitter function
End of explanation
path = "ex-data.csv";
exdata = pd.read_csv(path)
exdata.head()
grouped = exdata.groupby(['runner'])
stats = grouped.aggregate({'time':[np.std, np.mean]})
stats
errorbarjitter(exdata, 'runner', 'time', xlab = 'runner', ylab = 'time (s)')
plt.title('5 runners average course time')
Explanation: Example 1:
Here I created simple use case for the errorbarjitter function.
Consider a simple experiment in which 5 runners run a course 10 times. During each trial their elapsed time is recorded. The distribution of each runner's average time can be visualized using an errorbarjitter plot.
End of explanation
path = "iris.csv";
data = pd.read_csv(path)
data.head()
fig = plt.figure()
errorbarjitter(data, 'Species', 'Sepal.Length', xlab = 'species', ylab = 'sepal length')
plt.title('Sepal length by species')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Sepal.Width', xlab = 'species', ylab = 'sepal width')
plt.title('Sepal width by species')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Length', xlab = 'species', ylab = 'petal length')
plt.title('Petal length by species')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Width', xlab = 'species', ylab = 'petal width')
plt.title('Petal width by species')
Explanation: Iris dataset example
In this second example I use the iris dataset, obtained from Anderson[1].
It is simple to use errorbarjitter to plot the each of the metrics by speices as shown below.
End of explanation
sns.set_style('darkgrid')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Width', xlab = 'species', ylab = 'petal width')
plt.title('Petal width by species')
sns.set_style('whitegrid')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Width', xlab = 'species', ylab = 'petal width')
plt.title('Petal width by species')
sns.set_style('dark')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Width', xlab = 'species', ylab = 'petal width')
plt.title('Petal width by species')
sns.set_style('white')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Width', xlab = 'species', ylab = 'petal width')
plt.title('Petal width by species')
sns.set_style('ticks')
fig = plt.figure()
errorbarjitter(data, 'Species', 'Petal.Width', xlab = 'species', ylab = 'petal width')
plt.title('Petal width by species')
Explanation: References:
[1] errorbarjitter. David Stern. http://www.mathworks.com/matlabcentral/fileexchange/33658-errorbarjitter
[2] The data were collected by Anderson, Edgar (1935). The irises of the Gaspe Peninsula, Bulletin of the American Iris Society, 59, 2–5.
[3] Fisher, R. A. (1936) The use of multiple measurements in taxonomic problems. Annals of Eugenics, 7, Part II, 179–188.
[4] Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole. 
Appendix:
Theme options with sns.set_style:
'darkgrid' 
'whitegrid'
'dark' 
'white' 
'ticks'
End of explanation
path = "learning-data.csv";
learning = pd.read_csv(path)
sns.set_style('darkgrid')
fig = plt.figure()
errorbarjitter(learning, 'animal', 'pi', xlab = 'animal', ylab = 'performance index')
plt.title('learning assay')
plt.ylim(-1,1)
Explanation: Learning Index
End of explanation
<END_TASK>