Để thay đổi thuộc tính font (như in đậm) cho nhãn colorbar trong Matplotlib:
- Thiết lập figure size và autolayout.
- Tạo dữ liệu lưới x, y và giá trị z bằng NumPy.
- Hiển thị dữ liệu bằng imshow().
- Tạo colorbar từ instance ScalarMappable.
- Sử dụng axes của colorbar để thiết lập font properties (ví dụ: weight='bold').
- Hiển thị bằng show().
Ví dụ
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x, y = np.mgrid[-1:1:100j, -1:1:100j]
z = (x + y) * np.exp(-5.0 * (x ** 2 + y ** 2))
plt.imshow(z, extent=[-1, 1, -1, 1])
cb = plt.colorbar()
cb.set_label(label='my color bar label', weight='bold')
plt.show()
Kết quả
