核密度图可以看作是概率密度图,其纵轴可以粗略看做是数据出现的次数,与横轴围成的面积是一.
法一:seaborn的kdeplot函数专门用于画核密度估计图.
参考:https://www.jianshu.com/p/844f66d00ac1
https://yq.aliyun.com/articles/682843
import pandas as pd import numpy as np import matplotlib.pylab as plt import os import seaborn as sns ## 有时候要FQ才能下载 # df = pd.read_csv("https://github.com/selva86/datasets/raw/master/mpg_ggplot2.csv") # df.to_csv('../data/mpg_ggplot2.csv', index=False) df = pd.read_csv('../data/mpg_ggplot2.csv') print(df.info()) print(df.shape) # Draw Plot plt.figure(figsize=(16,10), dpi= 90) # dpi用于设置输出figure中所有字体的大小 # 将cyl列等于4的cty筛选出来做图 sns.kdeplot(df.loc[df['cyl'] == 4, "cty"], shade=True, color="g", label="Cyl=4