1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 数据科学入门与实战:Matplotlib绘图hist

数据科学入门与实战:Matplotlib绘图hist

时间:2024-06-28 17:40:06

相关推荐

数据科学入门与实战:Matplotlib绘图hist

直方图就是可以看数据整体分布情况

import numpy as npimport pandas as pdfrom pandas import Series,DataFrameimport matplotlib.pyplot as plt

s = Series(np.random.randn(1000))print(s)plt.hist(s)

调整柱子宽度

plt.hist(s,rwidth=0.5)

另一个例子

#另一个例子a = np.arange(10)print(a)plt.hist(a,rwidth=0.8)

re = plt.hist(s,rwidth=0.9)print(re)print(type(re))print(len(re))print('-----------')

(array([ 7., 26., 84., 202., 282., 205., 116., 58., 17., 3.]), array([-3.10819617, -2.44536828, -1.78254038, -1.11971249, -0.45688459,0.2059433 , 0.8687712 , 1.53159909, 2.19442699, 2.85725488,3.5278]), <a list of 10 Patch objects>)<class 'tuple'>3

print(re[0])#代表出现的次数print(re[1])#间隔print(re[2])#list十个矩形

20个矩形

#20个矩形~plt.hist(s,rwidth=0.9,bins=20)

plt.hist(s,rwidth=0.9,bins=20,color='r',stacked = False)#还可以变成水平的。。

#密度图kind默认为lines.plot(kind = 'kde')#密度图

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。