確定畫素的 matplotlib 軸大小
要確定畫素的軸大小,我們可以採取以下步驟 −
建立一個圖形和一組子圖,使用 subplots() 方法,fig 和 ax。
要獲取 DPI,使用 fig.dpi。列印詳細資訊。
在顯示框中查詢邊框框。
使用 bbox.width 和 bbox.height 查詢寬度和高度。
列印寬度和高度。
示例
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
print("Dot per inch(DPI) for the figure is: ", fig.dpi)
bbox = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
width, height = bbox.width, bbox.height
print("Axis sizes are(in pixels):", width, height)輸出
Dot per inch(DPI) for the figure is: 100.0 Axis sizes are(in pixels): 4.96 3.696
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP