0 频次直方图、频率直方图、累计直方图

就是统计每个数出现的次数。

plt.hist(x, bins=20,histtype='step', density=False, cumulative=True,  facecolor="g", alpha=0.75, rwidth=0.98)  

 

 

bins=20                 #将x中从最小值到最大的数分成20个相等的区间。也就是20个柱子。【例1】

                                也可以自己分区间,比如bins=[0,10,20,30,40,50,60]。这样就有6根柱子。

density=False       #如果不设置,默认是频次直方图。如果为True,则为频率直方图。【例2】

histtpe='step'         #如果不设置,则内部会填充,如果设置为了"step",则内部不会填充。【例1】【例3】

                                默认是histtype="bar"

cumulative=True   #为True则为累计直方图。默认为False。【例4】

rwidth=0.98          #柱子的宽度

 

 

例1:

Matplotlib(5)——直方图

 

结果:

Matplotlib(5)——直方图

 

 

例2:频率直方图。只需要增加参数density=True即可。

Matplotlib(5)——直方图

 

结果:

Matplotlib(5)——直方图

 

 

例3:不要内部的填充

Matplotlib(5)——直方图

 

 

Matplotlib(5)——直方图

 

 

例4:累计直方图

Matplotlib(5)——直方图

 

结果:

Matplotlib(5)——直方图

 

 

 

 

 

 

 

相关文章:

  • 2022-01-07
  • 2021-06-21
  • 2022-12-23
  • 2021-07-30
  • 2022-01-07
  • 2022-01-07
  • 2022-01-24
  • 2022-12-23
猜你喜欢
  • 2021-07-17
  • 2022-01-09
  • 2022-01-04
  • 2022-01-13
  • 2021-07-09
  • 2022-12-23
  • 2021-11-11
相关资源
相似解决方案