python - 绘制多轴对象数组

标签 python matplotlib plot

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

我需要将这些中的每一个绘制成四乘四的情节中的子情节。这就是我想要得到的(忽略这个图的尺寸)enter image description here

我尝试了简单的 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/

相关文章:

python - 如何在热图中设置中心颜色

python - Pyplot/matplotlib 线图 - 相同颜色

python - 从 Python 的 pandas 中的数据帧制作 matplotlib 散点图

python - GAE/P存储SES连接和线程安全

python - 设置 Plotly Bar graph x 轴的对齐方式

python - 检查未定义 __version__ 的 Python 库版本

python - 如何在使用 matplotlib 的情况下使用 pyinstaller

r - 将差异百分比添加到分组条形图中

Matlab 保存具有预定义大小的图形

python - __init__.py 和 __main__.py 有什么区别?