Python Matplotlib子图标题居中方法

在使用Matplotlib创建图表时,您可能需要将子图的标题居中显示。

为此,您可以使用set_title函数的loc参数,并将其设置为'center'

以下代码演示了如何将子图标题居中:

# 绘制轨迹
fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
ax.set_title('super Lorenz System - runge_kutta_lorenz', loc='center')
ax.plot(x[:, 0], x[:, 1], x[:, 2], lw=1)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

ax = fig.add_subplot(122, projection='3d')
ax.set_title('super Lorenz System - runge_kutta_lorenz', loc='center')
ax.plot(x[:, 0], x[:, 1], x[:, 3], lw=1)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('w')

plt.show()

通过将loc参数设置为'center',标题将在子图的水平方向上居中显示。

Python Matplotlib子图标题居中方法

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

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