Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีลบ relative offset ในแกน Matplotlib


ปิดการแสดงค่า offset บนแกน

ใช้ set_useOffset(False) บน formatter ของ major ticker

ขั้นตอน

  1. วาดเส้นด้วย list สองชุด
  2. ใช้ gca() ดึง axes ปัจจุบัน แล้วดึง X-axis instance 取得 formatter ของ major ticker ใช้ set_useOffset(False) ปิด offset
  3. แสดงด้วย show()

ตัวอย่างโค้ด

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()

ผลลัพธ์

วิธีลบ relative offset ในแกน Matplotlib