Python画直方图之seaborn

1.直方图。 

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p1=sns.distplot( df["sepal_length"] )
plt.show()

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p2=sns.distplot( df["sepal_length"], bins=20 )
plt.show()

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p1=sns.distplot( a=df["sepal_length"], hist=True, kde=False, rug=False )
plt.show()

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p2=sns.distplot( a=df["sepal_length"], hist=True, kde=True, rug=True )
plt.show()

 

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p3=sns.distplot( a=df["sepal_length"], rug=True,
    rug_kws={"color": "r", "alpha":0.3, "linewidth": 2, "height":0.2 }
    )
plt.show()

 

 

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p4=sns.distplot( a=df["sepal_length"], kde=True,
    kde_kws={"color": "g", "alpha":0.3, "linewidth": 5, "shade":True }
    )
plt.show()

 

 

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

sns.distplot( df["sepal_length"] , color="peru")
plt.show()

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p1=sns.distplot( df["sepal_length"] , color="skyblue", vertical=True)
plt.show()

 

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)

f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.15, .85)})

sns.boxplot(df["sepal_length"], ax=ax_box)
sns.distplot(df["sepal_length"], ax=ax_hist)
ax_box.set(xlabel='')

plt.show()

 

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

p1=sns.distplot( df["sepal_length"] , color="skyblue", label="Sepal Length")
p1=sns.distplot( df["sepal_width"] , color="red", label="Sepal Width")
plt.legend()
plt.show()

import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')

my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)

f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True)
sns.distplot( df["sepal_length"] , color="skyblue", ax=axes[0, 0])
sns.distplot( df["sepal_width"] , color="olive", ax=axes[0, 1])
sns.distplot( df["petal_length"] , color="gold", ax=axes[1, 0])
sns.distplot( df["petal_width"] , color="teal", ax=axes[1, 1])
plt.show()

 

 本博主新开公众号, 希望大家能扫码关注一下,十分感谢大家。

本文来自:https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值