python使用seaborn绘图工具:绘制直方图displot,密度图,散点图
小编写这篇文章的主要目的,是给各位广大的读者,去介绍一些知识,知识的内容主要是绘制相关的方图dispiot、密度图以及相关的散点图,具体内容,下面给大家详细解答。
一、直方图distplot()
import numpy as np import seaborn as sns import matplotlib.pyplot as plt import matplotlib import pandas as pd fig=plt.figure(figsize=(12,5)) ax1=plt.subplot(121) rs=np.random.RandomState(10)#设定随机数种子 s=pd.Series(rs.randn(100)*100) sns.distplot(s,bins=10,hist=True,kde=True,rug=True,norm_hist=False,color= 39;y 39;,label= 39;distplot 39;,axlabel= 39;x 39;) plt.legend() ax1=plt.subplot(122) sns.distplot(s,rug=True, hist_kws={ histtype : step , linewidth :1, alpha :1, color : g },#设置箱子的风格、线宽、透明度、颜色,风格包括: 39;bar 39;, 39;barstacked 39;, 39;step 39;, 39;stepfilled 39; kde_kws={ color : r , linewidth :1, label : KDE , 39;linestyle 39;: 39;-- 39;},#设置密度曲线颜色,线宽,标注、线形 rug_kws={ 39;color 39;: 39;r 39;})#设置数据频率分布颜色 plt.show()
函数及参数介绍:
distplot(a,bins=None,hist=True,kde=True,rug=False,fit=None,hist_kws=None, kde_kws=None,rug_kws=None,fit_kws=None,color=None,vertical=False, norm_hist=False,axlabel=None,label=None,ax=None)
a数据源
bins箱数hist、kde、rug是否显示箱数、密度曲线、数据分布,默认显示箱数和密度曲线不显示数据分析
{hist,kde,rug}_kws通过字典形式设置箱数、密度曲线、数据分布的各个特征
norm_hist直方图的高度是否显示密度,默认显示计数,如果kde设置为True高度也会显示为密度
color颜色
vertical是否在y轴上显示图标,默认为False即在x轴显示,即竖直显示
axlabel坐标轴标签
label直方图标签
二、密度图
2.1单个样本数据分布密度图
综上所述,关于这方面的内容就为大家介绍到这里了,希望可以为各位读者带来帮助。