gpt4 book ai didi

python - NumPy ndarray 的绘制方式与等效列表不同?

转载 作者:行者123 更新时间:2023-12-01 20:17:23 24 4
gpt4 key购买 nike

我期望“b”的绘制方式与“a”相同,但事实并非如此:

import matplotlib.pyplot as plt
import numpy as np

figure, axes = plt.subplots(nrows = 2, ncols = 1)

a = [[1, 2, 2, 3, 3, 3], [1, 1, 1, 2, 2, 3]]
b = np.array(object = a)

axes[0].hist(x = a, bins = np.arange(start = 0, stop = 5, step = 1), density = True)
axes[1].hist(x = b, bins = np.arange(start = 0, stop = 5, step = 1), density = True)

figure.show()

enter image description here

为什么?

最佳答案

matplotlib.axes.Axes.hist just does that 。很奇怪。

Multiple data can be provided via x as a list of datasets of potentially different length ([x0, x1, ...]), or as a 2-D ndarray in which each column is a dataset. Note that the ndarray form is transposed relative to the list form.

如果传递数据集列表,则每一行都是一个数据集。如果传递二维数组,则每一列都是一个数据集。

关于python - NumPy ndarray 的绘制方式与等效列表不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59606280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com