在 Matplotlib 中自動重新調整 ylim 和 xlim


要自動重新調整ylim xlim ,我們可以採取以下步驟 −

  • 要繪製一條線,請使用 plot() 方法和 0 到 10 的資料範圍。

  • 要自動調整xlim ylim ,我們可以將變數scale_factore=6.

  • 使用scale_factor(步驟 2)透過 xlim()ylim() 方法重新調整xlim ylim,分別。

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

示例

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.plot(range(0, 10))
scale_factor = 6
xmin, xmax = plt.xlim()
ymin, ymax = plt.ylim()
plt.xlim(xmin * scale_factor, xmax * scale_factor)
plt.ylim(ymin * scale_factor, ymax * scale_factor)
plt.show()

輸出

更新日期:2021 年 5 月 6 日

2K+ 瀏覽次數

開啟你的 職業生涯

完成該課程後獲得認證

開始
廣告
© . All rights reserved.