Подтвердить что ты не робот

Matplotlib, создавая сложную гистограмму из трех неравных массивов длины

Я хотел бы создать сложную гистограмму. Если у меня есть один двухмерный массив, состоящий из трех наборов данных с равной длиной, это просто. Код и изображение ниже:

import numpy as np
from matplotlib import pyplot as plt

# create 3 data sets with 1,000 samples
mu, sigma = 200, 25
x = mu + sigma*np.random.randn(1000,3)

#Stack the data
plt.figure()
n, bins, patches = plt.hist(x, 30, stacked=True, normed = True)
plt.show()

enter image description here

Однако, если я попробую аналогичный код с тремя наборами данных различной длины, результаты состоят в том, что одна гистограмма покрывает другую. Есть ли способ, которым я могу выполнить сложную гистограмму с наборами данных смешанной длины?

##Continued from above
###Now as three separate arrays
x1 = mu + sigma*np.random.randn(990,1)
x2 = mu + sigma*np.random.randn(980,1)
x3 = mu + sigma*np.random.randn(1000,1)

#Stack the data
plt.figure()
plt.hist(x1, bins, stacked=True, normed = True)
plt.hist(x2, bins, stacked=True, normed = True)
plt.hist(x3, bins, stacked=True, normed = True)
plt.show()

enter image description here

4b9b3361

Ответ 1

Ну, это просто. Мне просто нужно поместить три массива в список.

##Continued from above
###Now as three separate arrays
x1 = mu + sigma*np.random.randn(990,1)
x2 = mu + sigma*np.random.randn(980,1)
x3 = mu + sigma*np.random.randn(1000,1)

#Stack the data
plt.figure()
plt.hist([x1,x2,x3], bins, stacked=True, density=True)
plt.show()