確定畫素的 matplotlib 軸大小


要確定畫素的軸大小,我們可以採取以下步驟 −

  • 建立一個圖形和一組子圖,使用 subplots() 方法,fig ax

  • 要獲取 DPI,使用 fig.dpi。列印詳細資訊。

  • 在顯示框中查詢邊框框。

  • 使用 bbox.widthbbox.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

更新時間:06-May-2021

3K+ 瀏覽量

開啟你的 職業生涯

完成課程並獲得認證

開始吧
廣告
© . All rights reserved.