如何在對數-對數圖上使用 Matplotlib 在所有刻度線上顯示對數間隔網格線?


要在對數-對數圖上使用 matplotlib 在所有刻度線上顯示對數間隔網格線,我們可以採取以下步驟 -

  • 使用 numpy 為 x 和 y 建立資料點。
  • 使用 loglog 方法,在 X 和 Y 軸上均採用對數刻度的繪圖。
  • 使用 grid() 方法,以當前的行樣式佈置網格。提供 x 和 y 位置的列表。
  • 要顯示圖形,請使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.arange(0, 10, 1)
y = np.exp(x)
plt.loglog(x, y, c='r')
plt.grid(True, which="both", axis='x')
plt.show()

輸出

更新至: 2021-05-07

3 千 + 瀏覽次數

開始你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.