%matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn import preprocessing
import matplotlib.pyplot as plt
np.random.seed(sum(map(ord, "aesthetics")))
def sinplot(flip=1):
x=np.linspace(0,14,100)
for i in range(1,7):
plt.plot(x,np.sin(x+i*.5)*(7-i)*flip)
sinplot()
![png](output_1_0.png)
sns.set_style('whitegrid')
data=np.random.normal(size=(20,6))+np.arange(6)/2
sns.boxplot(data=data)
stock=pd.read_csv('sample.csv',index_col=0)
ohcl=stock.ix[:15,:4][::-1].T
sns.boxplot(ohcl)
# set_style()
sns.set_style("dark")
sns.boxplot(ohcl)
sns.set_style("ticks",{'xtick.direction': u'out'})
sns.boxplot(ohcl)
sns.despine()
![png](output_6_0.png)
sns.violinplot(ohcl,palette="deep")
sns.despine(offset=10,trim=True,left=True)
![png](output_7_0.png)
sns.axes_style()
{‘axes.axisbelow’: True, ‘axes.edgecolor’: ‘.15’, ‘axes.facecolor’: ‘white’, ‘axes.grid’: False, ‘axes.labelcolor’: ‘.15’, ‘axes.linewidth’: 1.25, ‘figure.facecolor’: ‘white’, ‘font.family’: [u’sans-serif’], ‘font.sans-serif’: [u’Arial’, u’Liberation Sans’, u’Bitstream Vera Sans’, u’sans-serif’], ‘grid.color’: ‘.8’, ‘grid.linestyle’: u’-‘, ‘image.cmap’: u’Greys’, ‘legend.frameon’: False, ‘legend.numpoints’: 1, ‘legend.scatterpoints’: 1, ‘lines.solid_capstyle’: u’round’, ‘text.color’: ‘.15’, ‘xtick.color’: ‘.15’, ‘xtick.direction’: u’out’, ‘xtick.major.size’: 6.0, ‘xtick.minor.size’: 3.0, ‘ytick.color’: ‘.15’, ‘ytick.direction’: u’out’, ‘ytick.major.size’: 6.0, ‘ytick.minor.size’: 3.0}
sns.set_context('talk') #notebook ,poster,talk
sns.boxplot(ohcl)
sns.set_style('darkgrid')
sns.regplot(x=stock.volume,y=stock.ma10,logx=True,x_estimator=np.mean)
sns.lmplot(x='ma5',y='ma20',data=stock,aspect=.5)
sns.lmplot(x='ma5',y='ma20',data=stock,aspect=.5)
sns.jointplot(x='ma10',y='price_change',data=stock,kind='reg')
#{ "scatter" | "reg" | "resid" | "kde" | "hex" }, optional
sns.jointplot(x='ma10',y='price_change',data=stock,kind='kde')
sns.jointplot(x='ma10',y='price_change',data=stock,kind='resid')
sns.jointplot(x='ma10',y='price_change',data=stock,kind='hex')
sns.jointplot(x='ma10',y='price_change',data=stock,kind='scatter')
titanic = sns.load_dataset("titanic")
tips = sns.load_dataset("tips")
iris = sns.load_dataset("iris")
tips
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
5 | 25.29 | 4.71 | Male | No | Sun | Dinner | 4 |
6 | 8.77 | 2.00 | Male | No | Sun | Dinner | 2 |
7 | 26.88 | 3.12 | Male | No | Sun | Dinner | 4 |
8 | 15.04 | 1.96 | Male | No | Sun | Dinner | 2 |
9 | 14.78 | 3.23 | Male | No | Sun | Dinner | 2 |
10 | 10.27 | 1.71 | Male | No | Sun | Dinner | 2 |
11 | 35.26 | 5.00 | Female | No | Sun | Dinner | 4 |
12 | 15.42 | 1.57 | Male | No | Sun | Dinner | 2 |
13 | 18.43 | 3.00 | Male | No | Sun | Dinner | 4 |
14 | 14.83 | 3.02 | Female | No | Sun | Dinner | 2 |
15 | 21.58 | 3.92 | Male | No | Sun | Dinner | 2 |
16 | 10.33 | 1.67 | Female | No | Sun | Dinner | 3 |
17 | 16.29 | 3.71 | Male | No | Sun | Dinner | 3 |
18 | 16.97 | 3.50 | Female | No | Sun | Dinner | 3 |
19 | 20.65 | 3.35 | Male | No | Sat | Dinner | 3 |
20 | 17.92 | 4.08 | Male | No | Sat | Dinner | 2 |
21 | 20.29 | 2.75 | Female | No | Sat | Dinner | 2 |
22 | 15.77 | 2.23 | Female | No | Sat | Dinner | 2 |
23 | 39.42 | 7.58 | Male | No | Sat | Dinner | 4 |
24 | 19.82 | 3.18 | Male | No | Sat | Dinner | 2 |
25 | 17.81 | 2.34 | Male | No | Sat | Dinner | 4 |
26 | 13.37 | 2.00 | Male | No | Sat | Dinner | 2 |
27 | 12.69 | 2.00 | Male | No | Sat | Dinner | 2 |
28 | 21.70 | 4.30 | Male | No | Sat | Dinner | 2 |
29 | 19.65 | 3.00 | Female | No | Sat | Dinner | 2 |
… | … | … | … | … | … | … | … |
214 | 28.17 | 6.50 | Female | Yes | Sat | Dinner | 3 |
215 | 12.90 | 1.10 | Female | Yes | Sat | Dinner | 2 |
216 | 28.15 | 3.00 | Male | Yes | Sat | Dinner | 5 |
217 | 11.59 | 1.50 | Male | Yes | Sat | Dinner | 2 |
218 | 7.74 | 1.44 | Male | Yes | Sat | Dinner | 2 |
219 | 30.14 | 3.09 | Female | Yes | Sat | Dinner | 4 |
220 | 12.16 | 2.20 | Male | Yes | Fri | Lunch | 2 |
221 | 13.42 | 3.48 | Female | Yes | Fri | Lunch | 2 |
222 | 8.58 | 1.92 | Male | Yes | Fri | Lunch | 1 |
223 | 15.98 | 3.00 | Female | No | Fri | Lunch | 3 |
224 | 13.42 | 1.58 | Male | Yes | Fri | Lunch | 2 |
225 | 16.27 | 2.50 | Female | Yes | Fri | Lunch | 2 |
226 | 10.09 | 2.00 | Female | Yes | Fri | Lunch | 2 |
227 | 20.45 | 3.00 | Male | No | Sat | Dinner | 4 |
228 | 13.28 | 2.72 | Male | No | Sat | Dinner | 2 |
229 | 22.12 | 2.88 | Female | Yes | Sat | Dinner | 2 |
230 | 24.01 | 2.00 | Male | Yes | Sat | Dinner | 4 |
231 | 15.69 | 3.00 | Male | Yes | Sat | Dinner | 3 |
232 | 11.61 | 3.39 | Male | No | Sat | Dinner | 2 |
233 | 10.77 | 1.47 | Male | No | Sat | Dinner | 2 |
234 | 15.53 | 3.00 | Male | Yes | Sat | Dinner | 2 |
235 | 10.07 | 1.25 | Male | No | Sat | Dinner | 2 |
236 | 12.60 | 1.00 | Male | Yes | Sat | Dinner | 2 |
237 | 32.83 | 1.17 | Male | Yes | Sat | Dinner | 2 |
238 | 35.83 | 4.67 | Female | No | Sat | Dinner | 3 |
239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
244 rows × 7 columns
sns.stripplot(x='day',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x42fce940>
sns.stripplot(x='day',y='total_bill',data=tips,jitter=True)
<matplotlib.axes._subplots.AxesSubplot at 0x430546a0>
sns.swarmplot(x='day',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x4235d860>
sns.swarmplot(x='day',y='total_bill',hue='sex',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x43503b00>
sns.swarmplot(x='size',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x435c7d30>
sns.swarmplot(x='total_bill',y='day',hue='time',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x3e010828>
sns.boxplot(x='day',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x3e1b2240>
hs_stock=pd.read_csv('hs_stock.csv',index_col=0)
sns.boxplot(x='code',y='ma10',data=hs_stock)
<matplotlib.axes._subplots.AxesSubplot at 0x517754e0>
sns.violinplot(x="total_bill", y="day", hue="time", data=tips);
sns.violinplot(x="total_bill", y="day", hue="time", data=tips,
bw=.1, scale="count", scale_hue=False);
sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True);
sns.violinplot(x="day", y="total_bill", data=tips, inner=None)
sns.swarmplot(x="day", y="total_bill", data=tips, color="w", alpha=.5);
sns.barplot(x="sex", y="survived", hue="class", data=titanic);
sns.countplot(x="deck", data=titanic, palette="Greens_d");
sns.factorplot(x="day", y="total_bill", hue="smoker", data=tips);
sns.factorplot(x="day", y="total_bill", hue="smoker", data=tips, kind="bar");
sns.factorplot(x="day", y="total_bill", hue="smoker",
col="time", data=tips, kind="swarm");
sns.factorplot(x="time", y="total_bill", hue="smoker",
col="day", data=tips, kind="box", size=4, aspect=.5);
g = sns.PairGrid(tips,
x_vars=["smoker", "time", "sex"],
y_vars=["total_bill", "tip"],
aspect=.75, size=3.5)
g.map(sns.violinplot, palette="pastel");
ohls=hs_stock.ix[:3000,:]
g=sns.FacetGrid(ohls,col='code')
g.map(sns.boxplot,'open',"ma5")
g.add_legend()
<seaborn.axisgrid.FacetGrid at 0x660e4f28>
gk=sns.PairGrid(ohls.ix[:,:9])
gk.map(plt.scatter)
<seaborn.axisgrid.PairGrid at 0xaa438828>