Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ตั้งค่า Title ให้ Bold ด้วย Font Times New Roman ใน Matplotlib

ใช้ fontname="Times New Roman" และ fontweight="bold" ใน set_title() หรือ title()

ตัวอย่างโค้ด


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()

ผลลัพธ์

Title แสดงแบบ Bold ด้วยฟอนต์ Times New Roman

ตั้งค่า Title ให้ Bold ด้วย Font Times New Roman ใน Matplotlib