使用“Times New Roman”同時為 Matplotlib 標題設定粗體


要在使用“Times New Roman”的同時將 Matplotlib 標題設定為粗體,我們可以使用 fontweight="bold"

步驟

  • 設定圖形大小,並調整子圖之間的和周圍的邊距。
  • 建立圖形和一組子圖。
  • 使用 numpy 建立 xy 資料點。
  • 使用 scatter() 方法繪製 xy 資料點。
  • 使用 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()

輸出

更新於:05-6-2021

9K+ 瀏覽量

開啟您的 職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.