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

Cách loại bỏ độ dịch chuyển tương đối (relative offset) trên trục Matplotlib

Tắt offset notation (ví dụ 1e3) trên trục bằng set_useOffset(False).

  • plt.plot([10, 101, 1001], [1, 2, 3]).
  • plt.gca().get_xaxis().get_major_formatter().set_useOffset(False).
  • show().

Ví dụ

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.plot([10, 101, 1001], [1, 2, 3])
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
plt.show()

Kết quả

Trục X hiển thị số nguyên 10, 101, 1001 thay vì ký hiệu khoa học 1e1, 1e2, 1e3.