seaborn

%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_billtipsexsmokerdaytimesize
016.991.01FemaleNoSunDinner2
110.341.66MaleNoSunDinner3
221.013.50MaleNoSunDinner3
323.683.31MaleNoSunDinner2
424.593.61FemaleNoSunDinner4
525.294.71MaleNoSunDinner4
68.772.00MaleNoSunDinner2
726.883.12MaleNoSunDinner4
815.041.96MaleNoSunDinner2
914.783.23MaleNoSunDinner2
1010.271.71MaleNoSunDinner2
1135.265.00FemaleNoSunDinner4
1215.421.57MaleNoSunDinner2
1318.433.00MaleNoSunDinner4
1414.833.02FemaleNoSunDinner2
1521.583.92MaleNoSunDinner2
1610.331.67FemaleNoSunDinner3
1716.293.71MaleNoSunDinner3
1816.973.50FemaleNoSunDinner3
1920.653.35MaleNoSatDinner3
2017.924.08MaleNoSatDinner2
2120.292.75FemaleNoSatDinner2
2215.772.23FemaleNoSatDinner2
2339.427.58MaleNoSatDinner4
2419.823.18MaleNoSatDinner2
2517.812.34MaleNoSatDinner4
2613.372.00MaleNoSatDinner2
2712.692.00MaleNoSatDinner2
2821.704.30MaleNoSatDinner2
2919.653.00FemaleNoSatDinner2
21428.176.50FemaleYesSatDinner3
21512.901.10FemaleYesSatDinner2
21628.153.00MaleYesSatDinner5
21711.591.50MaleYesSatDinner2
2187.741.44MaleYesSatDinner2
21930.143.09FemaleYesSatDinner4
22012.162.20MaleYesFriLunch2
22113.423.48FemaleYesFriLunch2
2228.581.92MaleYesFriLunch1
22315.983.00FemaleNoFriLunch3
22413.421.58MaleYesFriLunch2
22516.272.50FemaleYesFriLunch2
22610.092.00FemaleYesFriLunch2
22720.453.00MaleNoSatDinner4
22813.282.72MaleNoSatDinner2
22922.122.88FemaleYesSatDinner2
23024.012.00MaleYesSatDinner4
23115.693.00MaleYesSatDinner3
23211.613.39MaleNoSatDinner2
23310.771.47MaleNoSatDinner2
23415.533.00MaleYesSatDinner2
23510.071.25MaleNoSatDinner2
23612.601.00MaleYesSatDinner2
23732.831.17MaleYesSatDinner2
23835.834.67FemaleNoSatDinner3
23929.035.92MaleNoSatDinner3
24027.182.00FemaleYesSatDinner2
24122.672.00MaleYesSatDinner2
24217.821.75MaleNoSatDinner2
24318.783.00FemaleNoThurDinner2

244 rows × 7 columns

sns.stripplot(x='day',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x42fce940>

png

sns.stripplot(x='day',y='total_bill',data=tips,jitter=True)
<matplotlib.axes._subplots.AxesSubplot at 0x430546a0>

png

sns.swarmplot(x='day',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x4235d860>

png

sns.swarmplot(x='day',y='total_bill',hue='sex',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x43503b00>

png

sns.swarmplot(x='size',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x435c7d30>

png

sns.swarmplot(x='total_bill',y='day',hue='time',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x3e010828>

png

sns.boxplot(x='day',y='total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x3e1b2240>

png


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>

png

sns.violinplot(x="total_bill", y="day", hue="time", data=tips);

png

sns.violinplot(x="total_bill", y="day", hue="time", data=tips,
               bw=.1, scale="count", scale_hue=False);

png

sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True);

png

sns.violinplot(x="day", y="total_bill", data=tips, inner=None)
sns.swarmplot(x="day", y="total_bill", data=tips, color="w", alpha=.5);

png

sns.barplot(x="sex", y="survived", hue="class", data=titanic);

png

sns.countplot(x="deck", data=titanic, palette="Greens_d");

png

sns.factorplot(x="day", y="total_bill", hue="smoker", data=tips);

png

sns.factorplot(x="day", y="total_bill", hue="smoker", data=tips, kind="bar");

png

sns.factorplot(x="day", y="total_bill", hue="smoker",
               col="time", data=tips, kind="swarm");

png

sns.factorplot(x="time", y="total_bill", hue="smoker",
               col="day", data=tips, kind="box", size=4, aspect=.5);

png

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");

png

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>

png

gk=sns.PairGrid(ohls.ix[:,:9])
gk.map(plt.scatter)
<seaborn.axisgrid.PairGrid at 0xaa438828>

png

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值