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()

Python画直方图之seaborn_第1张图片

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

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

Python画直方图之seaborn_第2张图片

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()

Python画直方图之seaborn_第3张图片

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()

 Python画直方图之seaborn_第4张图片

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()

 Python画直方图之seaborn_第5张图片

 

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()

 Python画直方图之seaborn_第6张图片

 

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

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

Python画直方图之seaborn_第7张图片

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()

 Python画直方图之seaborn_第8张图片

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()

Python画直方图之seaborn_第9张图片

 

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()

Python画直方图之seaborn_第10张图片

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()

 Python画直方图之seaborn_第11张图片

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

Python画直方图之seaborn_第12张图片

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

你可能感兴趣的:(python画图)