In [1]:
%matplotlib inline
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import scipy as sp
sns.set(style='ticks', context='poster', font_scale=1)
In [2]:
data = pd.read_csv('/Users/Pamsfwang/Documents/Psych45/WWW/demos/Semantic_demo.csv',
index_col=[0],header=[0, 1], skipinitialspace=True)
data.head()
Out[2]:
In [3]:
print 'We currently have data from ' + str(data.count()[0]) + ' students.'
In [4]:
df = data.unstack().reset_index(name='rating')
#df.rename(columns={'Timestamp': 'item', 'level_2': 'timestamp'}, inplace=True)
df.rename(columns={'level_0': 'category', 'Timestamp': 'item', 'level_2': 'timestamp'}, inplace=True)
df.head()
Out[4]:
In [5]:
category_list = df.category.unique()
In [ ]:
f, axes = plt.subplots(ncols=len(category_list), figsize=(15, 3), sharey=True)
plt.locator_params(nbins=5)
first = True
for ax, category in zip(axes, category_list):
ax.hlines(y=1, xmin=-1, xmax=4, linestyles='dashed', colors='green')
g = sns.pointplot(x='item', y='rating', ax=ax, jitter=True, alpha=.4,
ci=95, palette=['darkgray'],
data=df.loc[df.category == category])
g.set_title(category)
g.set_ylabel('')
g.set_xlabel('')
g.set_xticklabels(df.loc[df.category == category].item.unique(), rotation=90)
f.text(0.07, 0.5, 'Rating', va='center', rotation='vertical', fontsize='xx-large')
sns.despine()
In [ ]:
f, ax = plt.subplots(ncols=1, figsize=(10, 4), sharey=True)
g = sns.stripplot(x='item', y='rating', jitter=True, alpha=.1, size=12, linewidth=1,
data=df.loc[df.category == 'fruit'],
order=['apple', 'strawberry', 'fig'],
palette=['limegreen', 'hotpink', 'mediumpurple'], ax=ax)
g.set_xlabel('')
In [ ]:
f, ax = plt.subplots(ncols=1, figsize=(10, 4), sharey=True)
g = sns.stripplot(x='item', y='rating', jitter=True, alpha=.1, size=12, linewidth=1,
data=df.loc[df.category == 'sport'],
order=['football', 'hockey', 'wrestling'],
palette=['peru', 'black', 'blue'], ax=ax)
g.set_xlabel('')
In [ ]:
f, ax = plt.subplots(ncols=1, figsize=(10, 4), sharey=True)
g = sns.stripplot(x='item', y='rating', jitter=True, alpha=.1, size=12, linewidth=1,
data=df.loc[df.category == 'vehicle'],
order=['car', 'boat', 'tricycle'],
palette=['gray', 'deepskyblue', 'crimson'], ax=ax)
g.set_xlabel('')
In [ ]:
f, ax = plt.subplots(ncols=1, figsize=(10, 4), sharey=True)
g = sns.stripplot(x='item', y='rating', jitter=True, alpha=.1, size=12, linewidth=1,
data=df.loc[df.category == 'bird'],
order=['ostrich', 'wren', 'robin'],
palette=['peru', 'black', 'blue'], ax=ax)
g.set_xlabel('')
In [ ]: