我有一个 4x4 numpy 数组,ax
,其中每个元素都是一个 <class 'matplotlib.axes._subplots.AxesSubplot'>
目的。
这就是ax
看起来
>>> ax
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x124366f98>,
<matplotlib.axes._subplots.AxesSubplot object at 0x1246d0160>,
<matplotlib.axes._subplots.AxesSubplot object at 0x124392710>,
<matplotlib.axes._subplots.AxesSubplot object at 0x125c0cdd8>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x1270032b0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x127124908>,
<matplotlib.axes._subplots.AxesSubplot object at 0x12afcaf98>,
<matplotlib.axes._subplots.AxesSubplot object at 0x127176668>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x127170cf8>,
<matplotlib.axes._subplots.AxesSubplot object at 0x124b1e3c8>,
<matplotlib.axes._subplots.AxesSubplot object at 0x1270c2a58>,
<matplotlib.axes._subplots.AxesSubplot object at 0x124aeb128>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x124b0d7b8>,
<matplotlib.axes._subplots.AxesSubplot object at 0x12af52e48>,
<matplotlib.axes._subplots.AxesSubplot object at 0x124a96518>,
<matplotlib.axes._subplots.AxesSubplot object at 0x12910cba8>]],
dtype=object)
我需要将这些中的每一个绘制成四乘四的情节中的子情节。这就是我想要得到的(忽略这个图的尺寸)
我尝试了简单的 plt.show(ax)
但自从 ax
以来我显然遇到了错误是 AxesSubplot
的集合类(class)。我还尝试遍历 ax
数组和绘图,但我得到了与我运行时相同的错误 plt.show(ax)
.这是错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 253, in show
return _show(*args, **kw)
File "/usr/local/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 207, in show
if block:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
如何绘制 AxesSubplot
的集合上课?
最佳答案
您必须遍历 axesSubplot
实例并调用 fig.axes.append(ax)
关于python - 绘制多轴对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57721822/