簡體   English   中英

我怎樣才能在同一張圖上 plot 4 個直方圖

[英]how can I plot 4 histograms on the same graph


我有以下問題:
我在 matplotlib.pyplot 中使用 hist()
我正在嘗試在同一張圖上創建 4 個直方圖。 以及它們中的每一個的近似高斯。
我怎樣才能 plot 在同一張圖上的 4 個直方圖,而不會相互阻擋(並排)? 有任何想法嗎?

matplotlib 文檔中有幾個示例。 這個看起來像是回答了你的問題:

import numpy as np
import pylab as P
#
# first create a single histogram
#
mu, sigma = 200, 25
x = mu + sigma*P.randn(10000)
#
# finally: make a multiple-histogram of data-sets with different length
#
x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

# and exercise the weights option by arbitrarily giving the first half
# of each series only half the weight of the others:

w0 = np.ones_like(x0)
w0[:len(x0)/2] = 0.5
w1 = np.ones_like(x1)
w1[:len(x1)/2] = 0.5
w2 = np.ones_like(x2)
w0[:len(x2)/2] = 0.5



P.figure()

n, bins, patches = P.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')

P.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM