日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python使用seaborn繪圖直方圖displot,密度圖,散點圖_python

作者:xiaozheng123121 ? 更新時間: 2022-09-06 編程語言

一、直方圖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='y', label='distplot', axlabel='x')
plt.legend()

ax1 = plt.subplot(122)
sns.distplot(s, rug=True,
             hist_kws={"histtype": "step", "linewidth": 1, "alpha": 1, "color": "g"},  # 設置箱子的風格、線寬、透明度、顏色,風格包括:'bar', 'barstacked', 'step', 'stepfilled'
             kde_kws={"color": "r", "linewidth": 1, "label": "KDE", 'linestyle': '--'},   # 設置密度曲線顏色,線寬,標注、線形
             rug_kws={'color': 'r'})  # 設置數據頻率分布顏色
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 單個樣本數據分布密度圖

原文鏈接:https://blog.csdn.net/weixin_46713695/article/details/125773614

欄目分類
最近更新