Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Đặt tiêu đề Matplotlib in đậm với font Times New Roman

Để đặt tiêu đề Matplotlib in đậm dùng "Times New Roman", ta dùng fontweight="bold".

Các bước

  • Thiết lập kích thước hình và điều chỉnh khoảng đệm giữa và xung quanh subplots.
  • Tạo hình và tập subplots.
  • Tạo điểm dữ liệu x, y dùng numpy.
  • Vẽ x, y dùng scatter().
  • Đặt tiêu đề đồ thị dùng fontname="Times New Roman" và fontweight="bold".
  • Hiển thị hình dùng show().

Ví dụ

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

Kết quả

Đặt tiêu đề Matplotlib in đậm với font Times New Roman