溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

關(guān)于python中plt.hist參數(shù)的使用詳解

發(fā)布時間:2020-09-29 15:30:52 來源:腳本之家 閱讀:1133 作者:我是賣報的小行家啦啦啦 欄目:開發(fā)技術(shù)

如下所示:

 matplotlib.pyplot.hist( 
  x, bins=10, range=None, normed=False,  
  weights=None, cumulative=False, bottom=None,  
  histtype=u'bar', align=u'mid', orientation=u'vertical',  
  rwidth=None, log=False, color=None, label=None, stacked=False,  
  hold=None, **kwargs) 

x : (n,) array or sequence of (n,) arrays

這個參數(shù)是指定每個bin(箱子)分布的數(shù)據(jù),對應(yīng)x軸

bins : integer or array_like, optional

這個參數(shù)指定bin(箱子)的個數(shù),也就是總共有幾條條狀圖

normed : boolean, optional

If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e.,n/(len(x)`dbin)

這個參數(shù)指定密度,也就是每個條狀圖的占比例比,默認(rèn)為1

color : color or array_like of colors or None, optional

這個指定條狀圖的顏色

我們繪制一個10000個數(shù)據(jù)的分布條狀圖,共50份,以統(tǒng)計10000分的分布情況

  """ 
  Demo of the histogram (hist) function with a few features. 
   
  In addition to the basic histogram, this demo shows a few optional features: 
   
    * Setting the number of data bins 
    * The ``normed`` flag, which normalizes bin heights so that the integral of 
     the histogram is 1. The resulting histogram is a probability density. 
    * Setting the face color of the bars 
    * Setting the opacity (alpha value). 
   
  """ 
  import numpy as np 
  import matplotlib.mlab as mlab 
  import matplotlib.pyplot as plt 
   
   
  # example data 
  mu = 100 # mean of distribution 
  sigma = 15 # standard deviation of distribution 
  x = mu + sigma * np.random.randn(10000) 
   
  num_bins = 50 
  # the histogram of the data 
  n, bins, patches = plt.hist(x, num_bins, normed=1, facecolor='blue', alpha=0.5) 
  # add a 'best fit' line 
  y = mlab.normpdf(bins, mu, sigma) 
  plt.plot(bins, y, 'r--') 
  plt.xlabel('Smarts') 
  plt.ylabel('Probability') 
  plt.title(r'Histogram of IQ: $\mu=100$, $\sigma=15$') 
   
  # Tweak spacing to prevent clipping of ylabel 
  plt.subplots_adjust(left=0.15) 
  plt.show() 

關(guān)于python中plt.hist參數(shù)的使用詳解

以上這篇關(guān)于python中plt.hist參數(shù)的使用詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI