CASE3.1
设置标题与坐标轴名称
示例同时设置主标题与两个坐标轴名称,并通过 pad 和 labelpad 调整间距,避免文字与刻度重叠。
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [3.2, 4.5, 4.1, 5.8, 6.4]
fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(x, y, marker='o', color='#1E3050')
# 设置标题、坐标轴名称与间距
ax.set_title('季度客户增长率', fontsize=17, pad=16)
ax.set_xlabel('季度序号', labelpad=10)
ax.set_ylabel('增长率 / %', labelpad=10)
plt.tight_layout()
plt.show()