Các bước
- Thiết lập kích thước hình và padding.
- Tạo dữ liệu ngẫu nhiên ma trận 5x5.
- Hiển thị hình ảnh bằng
imshow().
- Dùng
tick_params() để di chuyển nhãn: labelbottom=False, labeltop=True.
- Gọi
show().
Ví dụ
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
data = np.random.rand(5, 5)
plt.imshow(data, cmap="copper")
plt.tick_params(axis='both', which='major',
labelsize=10, labelbottom=False,
bottom=True, top=False, labeltop=True)
plt.show()
Kết quả
