在建立 matplotlib 圖形時,您可能會遇到軸偏移顯示為小數的問題。例如,奈秒測量值在 y 軸上顯示為 4.4e-8 而不是 44e-9,天計數在 x 軸上顯示為 5.54478e4 而不是 55447。
要解決此問題,您可以使用 ScalarFormatter 和 useOffset=False 來停用特定軸的偏移。具體方法如下:
import matplotlib.pyplot as plt fig, ax = plt.subplots() # Disable offset for y-axis y_formatter = ScalarFormatter(useOffset=False) ax.yaxis.set_major_formatter(y_formatter)
對於x軸,可以使用:
# Disable offset for x-axis x_formatter = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(x_formatter)
透過這些更改,軸將根據需要顯示偏移量的整數。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3