Để điều chỉnh kích thước chữ của ký hiệu khoa học (scientific notation) trên trục tọa độ, ta dùng ticklabel_format() với style="sci".
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu x, y có giá trị lớn.
- Vẽ dữ liệu bằng plot().
- Định dạng nhãn trục x: plt.ticklabel_format(axis="x", style="sci", scilimits=(0,0)).
- Hiển thị bằng show().
Ví dụ
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = [10000, 20000, 300000, 34, 1, 10000]
y = [1, 2, 0, 4, 1, 5]
plt.plot(x, y, color='red')
plt.ticklabel_format(axis="x", style="sci", scilimits=(0, 0))
plt.show()
Kết quả
