在 Matplotlib 中,可以使用 'subplot' 函数将多个子图组合在一起。

例如,要创建一个包含两个子图的图形,可以这样写:

import matplotlib.pyplot as plt

# 创建两个子图
fig, axes = plt.subplots(nrows=2, ncols=1)

# 在第一个子图中绘制数据
axes[0].plot([1, 2, 3], [4, 5, 6])

# 在第二个子图中绘制数据
axes[1].plot([1, 2, 3], [7, 8, 9])

plt.show()

'subplot' 函数返回一个包含两个子图的图形对象和一个包含每个子图的 Axes 对象的数组。然后,可以使用 Axes 对象来在每个子图中绘制数据。

有关 'subplot' 函数的更多信息,请参考 Matplotlib 文档: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplot.html

Matplotlib 多子图组合:使用 'subplot' 函数

原文地址: https://www.cveoy.top/t/topic/oEH4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录