原文链接:http://www.juzicode.com/archives/3139
错误提示:
pyplot.hist()绘制直方图时提示:ValueError: x must have 2 or fewer dimensions
#juzicode.com,#VX:桔子code
import numpy as np
import matplotlib.pyplot as plt
plt.rc('font',family='Youyuan',size='9')
plt.rc('axes',unicode_minus='False')
a = np.random.randn(2000,2,3)
print('a.shape=',a.shape)
plt.hist(a,bins=50)
plt.title('正态分布 by桔子code')
plt.show()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-60-e1963ebdf16f> in <module>
7 a = np.random.randn(2000,2,3)
8 print('a.shape=',a.shape)
----> 9 plt.hist(a,bins=50)
10 plt.title('正态分布 by桔子code')
11 plt.show()
d:\python\python38\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, densi

该博客主要介绍了在使用matplotlib的pyplot.hist()函数绘制直方图时遇到的错误:ValueError:xmusthave2orfewerdimensions。错误原因是传入的numpy数组维度超过了2。解决方法是将三维数组拆分为多个二维数组,分别绘制直方图。示例代码展示了如何拆分并绘制每个二维数组的直方图。
最低0.47元/天 解锁文章
1684

被折叠的 条评论
为什么被折叠?



