在 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()
輸出

廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP