Các bước
- Thiết lập kích thước hình và padding.
- Khởi tạo biến
N cho số mẫu.
- Tạo dữ liệu
x, y bằng numpy.
- Vẽ đồ thị bằng
plot().
- Tùy chỉnh nhãn trục X với
fontweight, color, fontsize, horizontalalignment.
- Gọi
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
N = 100
x = np.random.rand(N)
y = np.random.rand(N)
plt.plot(x, y, 'r*')
plt.xlabel('X-axis Label', fontweight='bold', color='orange', fontsize='17', horizontalalignment='center')
plt.show()
Kết quả
