防止在 matplotlib.pyplot 中使用科學計數法


要防止使用科學計數法,我們必須在 ticklabel_format 方法中傳遞 style='plain'。

步驟

  • 傳遞兩個列表來利用 plot() 方法繪製一條線。

  • 使用 ticklabel_format() 方法加上 style='plain'。如果未設定引數,相應格式器的屬性將保持不變。Style='plain' 會關閉科學計數法。

  • 要顯示圖形,請使用 plt.show() 方法。

範例

from matplotlib import pyplot as plt
plt.plot([1, 2, 3, 4, 5], [11, 12, 13, 14, 15])
plt.ticklabel_format(style='plain')    # to prevent scientific notation.
plt.show()

輸出

更新於: 2021 年 3 月 17 日

17K+ 瀏覽

開啟您的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.