第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

選擇數(shù)據(jù)點相對較少的直方圖的 bin

選擇數(shù)據(jù)點相對較少的直方圖的 bin

不負相思意 2021-11-02 20:04:09
考慮在 matplotlib 中具有多個直方圖的圖,如下所示:#! /usr/bin/env python3import matplotlib.pyplot as pltimport random# Use the same seed for reproducibility.random.seed(10586)data1 = [random.gauss(1e-4, 3e-2) for _ in range(10**3)] + [0.3]data2 = [random.gauss(1e-2, 3e-3) for _ in range(10**3)] + [0.4]data3 = [0.2]if __name__ == '__main__':    plt.xlim(xmin=0, xmax=0.8)    plt.yscale('log')    n1, bins1, patches1 = plt.hist(data1, bins='auto', alpha=0.6)    n2, bins2, patches2 = plt.hist(data2, bins='auto', alpha=0.6)    n3, bins3, patches3 = plt.hist(data3, bins='auto', alpha=0.6)    bin_options = ['auto', 'fd', 'doane', 'scott', 'rice', 'sturges', 'sqrt']    plt.show()然而,第三個數(shù)據(jù)集只有一個數(shù)據(jù)點,所以當(dāng)我們使用時,plt.hist(data3, bins='auto') 我們得到一個橫跨 x 范圍的長條,并且看不到它的值為 0.2:(這在只有一個數(shù)據(jù)點時最為明顯,但對于例如兩個或三個數(shù)據(jù)點來說也是一個問題。)避免這種情況的一種方法是重新使用另一個數(shù)據(jù)集的箱。例如,對于plt.hist(data3, bins=bins1),我們可以看到data3就好了:但是,如果我們通過 使用其他數(shù)據(jù)集bins=bins2,則 bin 太窄,我們根本看不到data3:我們?nèi)绾未_保具有相對較少點的直方圖可見,但仍能看到其在 x 軸上的值?
查看完整描述

1 回答

?
慕后森

TA貢獻1802條經(jīng)驗 獲得超5個贊

考慮在 matplotlib 中具有多個直方圖的圖,如下所示:


#! /usr/bin/env python3

import matplotlib.pyplot as plt

import random


# Use the same seed for reproducibility.

random.seed(10586)


data1 = [random.gauss(1e-4, 3e-2) for _ in range(10**3)] + [0.3]

data2 = [random.gauss(1e-2, 3e-3) for _ in range(10**3)] + [0.4]

data3 = [0.2]


if __name__ == '__main__':

    plt.xlim(xmin=0, xmax=0.8)

    plt.yscale('log')

    n1, bins1, patches1 = plt.hist(data1, bins='auto', alpha=0.6)

    n2, bins2, patches2 = plt.hist(data2, bins='auto', alpha=0.6)

    n3, bins3, patches3 = plt.hist(data3, bins='auto', alpha=0.6)

    bin_options = ['auto', 'fd', 'doane', 'scott', 'rice', 'sturges', 'sqrt']

    plt.show()

然而,第三個數(shù)據(jù)集只有一個數(shù)據(jù)點,所以當(dāng)我們使用時,plt.hist(data3, bins='auto') 我們得到一個橫跨 x 范圍的長條,并且看不到它的值為 0.2:

http://img1.sycdn.imooc.com//618129740001186205360242.jpg

或者histtype="stepfilled"用來創(chuàng)建一個多邊形,因為無論如何單個條形都無法與那么多垃圾箱區(qū)分開來,

n2, bins2, patches2 = plt.hist(data2, bins='auto', alpha=0.6, histtype="stepfilled")

http://img1.sycdn.imooc.com//618129800001db3005460245.jpg

后者還具有服從 alpha 的優(yōu)點,否則由于條形的重疊而看不到它。此外,它應(yīng)該更快地繪制單個形狀而不是大約 1000 個條形圖。


查看完整回答
反對 回復(fù) 2021-11-02
  • 1 回答
  • 0 關(guān)注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號