如何在 Matplotlib 圖表的左下角顯示 (0,0)?


要在 Matplotlib 圖表的左下角顯示 (0,0),我們可以使用 xlim()ylim() 方法。

步驟

  • 設定圖形大小並調整子圖之間及周圍的填充。

  • xy 建立資料點列表。

  • 繪製 xy 資料點。

  • 設定 xy 軸刻度。

  • 要顯示圖形,請使用 Show() 方法。

示例

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

x = np.array([0, 1, 3, 2, 1, 5])
y = np.array([0, 2, 4, 4, 3, 3])

plt.plot(x, y)

plt.xlim([0, max(x)+0.5])
plt.ylim([0, max(y)+0.5])

plt.show()

輸出

將會產生以下輸出 −

更新於: 2021-10-08

12K+ 瀏覽量

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.