Matplotlib子图中的水平空间操作
为了在Matplotlib子图中对水平空间进行操作,我们可以在不进行紧密图布局的情况下使用 subplots_adjust() 方法中的 wspace=1 。
步骤
- 设置图形大小并调整子图之间和周围的填充。
- 使用NumPy创建 x 和 y 数据点。
- 创建具有4个索引的图和子图集合。
- 为了调整垂直空间,我们可以使用 wspace=1 。
- 使用 show() 方法显示图形。
示例
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(wspace=1)
plt.show()