gpt4 book ai didi

python - 如何将 matplotlib 图形组合成多个子图?

转载 作者:行者123 更新时间:2023-12-05 06:11:15 27 4
gpt4 key购买 nike

使用 matplotib 我有几个 Figure 对象从不同的绘图函数返回。为每个图生成特定格式的图很昂贵,[fig1, fig2, fig3, fig4]

我需要以不同的布局排列它们。例如,包含 fig1、fig3、fig4 的列;包含所有数字的一行;所有图形的 2x2 网格,依此类推。我查看了 pyplot.subplots,但这会返回一个无法设置的轴数组。

如何将这些单独的图形对象组合成多个子图?

我的实际案例有 20 多个昂贵的图形需要以多种不同的布局排列,所以我真的无法为每个布局组合重新绘制图形。

最佳答案

你的意思是像 THIS 这样的东西吗? :

import matplotlib.pyplot as plt
fig, axs = plt.subplots(ncols=3, nrows=3)
gs = axs[1, 2].get_gridspec()
# remove the underlying axes
for ax in axs[1:, -1]:
ax.remove()
axbig = fig.add_subplot(gs[1:, -1])
axbig.annotate('Big Axes \nGridSpec[1:, -1]', (0.1, 0.5),
xycoords='axes fraction', va='center')
fig.tight_layout()
plt.show()

关于python - 如何将 matplotlib 图形组合成多个子图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64069622/

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