本文簡要介紹 python 語言中 matplotlib.figure.figaspect
的用法。
-
計算具有指定縱橫比的圖形的寬度和高度。
雖然高度取自
rcParams["figure.figsize"]
(默認值:[6.4, 4.8]
),但調整寬度以匹配所需的縱橫比。此外,確保寬度在 [4., 16.] 範圍內,高度在 [2., 16.] 範圍內。如有必要,將調整默認高度以確保這一點。- 參數:
- arg 浮點數或二維數組
-
如果是浮點數,這將定義縱橫比(即比率高度/寬度)。在陣列的情況下,縱橫比是行數/列數,因此陣列可以不失真地擬合在圖中。
- 返回:
- width, height 浮點數
-
以英寸為單位的圖形大小。
注意
如果要在圖形中創建一個仍保留縱橫比的軸,請確保創建具有相等寬度和高度的軸。請參閱下麵的示例。
感謝 Fernando Perez 提供此函數。
例子
畫一個高兩倍寬的圖形:
w, h = figaspect(2.) fig = Figure(figsize=(w, h)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) ax.imshow(A, **kwargs)
為數組製作一個具有正確方麵的圖形:
A = rand(5, 3) w, h = figaspect(A) fig = Figure(figsize=(w, h)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) ax.imshow(A, **kwargs)
用法
matplotlib.figure.figaspect(arg)
相關用法
- Python matplotlib figlegend用法及代碼示例
- Python matplotlib figimage用法及代碼示例
- Python matplotlib flatten用法及代碼示例
- Python matplotlib from_any用法及代碼示例
- Python matplotlib axvspan用法及代碼示例
- Python matplotlib Axes.get_legend_handles_labels用法及代碼示例
- Python matplotlib AbstractMovieWriter用法及代碼示例
- Python matplotlib triplot用法及代碼示例
- Python matplotlib StarPolygonCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.hist用法及代碼示例
- Python matplotlib boxplot用法及代碼示例
- Python matplotlib subplots用法及代碼示例
- Python matplotlib InsetPosition用法及代碼示例
- Python matplotlib ToolManager.toolmanager_disconnect用法及代碼示例
- Python matplotlib Figure.set_size_inches用法及代碼示例
- Python matplotlib Axes.step用法及代碼示例
- Python matplotlib Axes.contour用法及代碼示例
- Python matplotlib LassoSelector用法及代碼示例
- Python matplotlib BrokenBarHCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.plot用法及代碼示例
- Python matplotlib Axes.semilogx用法及代碼示例
- Python matplotlib Axes.semilogy用法及代碼示例
- Python matplotlib MovieWriterRegistry.register用法及代碼示例
- Python matplotlib PolyQuadMesh.set_hatch用法及代碼示例
- Python matplotlib warn_deprecated用法及代碼示例
注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.figure.figaspect。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。