当前位置: 移动技术网 > IT编程>脚本编程>Python > Python画直方图之seaborn

Python画直方图之seaborn

2020年07月03日  | 移动技术网IT编程  | 我要评论

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 

本文地址:https://blog.csdn.net/weixin_41869644/article/details/107072375

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网