gpt4 book ai didi

python - 绘制多轴对象数组

转载 作者:行者123 更新时间:2023-11-28 18:56:32 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com