在Matplotlib中以绝对方式(而非相对方式)调整子图的高度
要在Matplotlib中以绝对方式调整一个子图的高度,可以按照以下步骤进行−
- 将图的大小和子图之间以及周围的填充调整好。
- 创建新的图或激活现有的图。
- 为子图的绝对高度使用 Axes() 类。
- 将一个轴添加到图表中。
- 在轴上绘制数据点。
- 要显示图像,请使用 show() 方法。
示例
from matplotlib import pyplot as pl
pl.rcParams["figure.figsize"] = [7.50, 4.50]
pl.rcParams["figure.autolayout"] = True
figure = pl.figure()
axes = pl.Axes(figure, [.4, .6, .25, .25])
figure.add_axes(axes)
pl.plot([1, 2, 3, 4], [1, 2, 3, 4])
axes = pl.Axes(figure, [.4, .1, .25, .25])
figure.add_axes(axes)
pl.plot([1, 2, 3, 4], [1, 2, 3, 4])
pl.show()