我有一个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)

我需要把这些画成四乘四的副图。这就是我想要得到的(忽略这个图的尺寸)python - 绘制多轴对象数组-LMLPHP
我尝试了简单的plt.show(ax)但是我显然遇到了错误,因为axAxesSubplot类的集合。我还尝试了循环遍历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)

09-11 19:36