欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python画直方图之seaborn

程序员文章站 2022-10-10 15:44:44
1.柱形图。import seaborn as snsimport matplotlib.pyplot as pltdf = sns.load_dataset('iris')p1=sns.distplot( df["sepal_length"] )plt.show()import seaborn as snsimport matplotlib.pyplot as pltdf = sns.load_dataset('iris')p2=sns.distplot( df["se....

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

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

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

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

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

 

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

 

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

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

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

 

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

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

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

Python画直方图之seaborn

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

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