使用“Times New Roman”设置加粗的 Matplotlib 标题
要在使用“Times New Roman”字体的情况下设置加粗的 Matplotlib 标题,我们可以使用 fontweight=”bold” 。
步骤
- 设置图形大小并调整子图之间和周围的间距。
- 创建一个图形和一组子图。
- 使用 numpy 创建 x 和 y 数据点。
- 使用 scatter() 方法绘制 x 和 y 数据点。
- 使用 fontname=”Times New Roman” 和 fontweight=”bold” 设置绘图标题。
- 使用 show() 方法显示图形。
示例
import numpy as np
from matplotlib import pyplot as plt, font_manager as fm
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots()
x = np.random.rand(100)
y = np.random.rand(100)
ax.scatter(x, y, c=y, marker="v")
ax.set_title('Scatter Plot With Random Points', fontname="Times New Roman", size=28,fontweight="bold")
plt.show()