所以我很确定你的问题与数组train_x的格式有关。我用10000行6列的数组尝试了你的程序,它工作得很好,所以问题不是大小。出于某种原因,len(x_train)或len(x_train[0])中的一个是0。我之所以这么认为是因为:
您得到的值错误来自matplotlib.axes.\u子块模块,该模块处理在一个大图中绘制许多小子块(因此每个小直方图)。模块代码如下:"""
*rows*, *cols*, *num* are arguments where
the array of subplots in the figure has dimensions *rows*,
*cols*, and where *num* is the number of the subplot
being created. *num* starts at 1 in the upper left
corner and increases to the right.
"""
rows, cols, num = args
rows = int(rows)
cols = int(cols)
if isinstance(num, tuple) and len(num) == 2:
num = [int(n) for n in num]
self._subplotspec = GridSpec(rows, cols)[num[0] - 1:num[1]]
else:
if num < 1 or num > rows*cols:
raise ValueError(
"num must be 1 <= num <= {maxn}, not {num}".fo