本文簡要介紹 python 語言中 matplotlib.pyplot.subplot
的用法。
-
將軸添加到當前圖窗或檢索現有軸。
這是
Figure.add_subplot
的包裝器,它在使用隱式 API 時提供額外的行為(請參閱注釋部分)。調用簽名:
subplot(nrows, ncols, index, **kwargs) subplot(pos, **kwargs) subplot(**kwargs) subplot(ax)
- 參數:
- *args int, (int, int,
index
), 或SubplotSpec
, 默認: (1, 1, 1) -
由其中之一說明的子圖的位置
-
三個整數(
nrows
、ncols
、index
)。子圖將在具有nrows
行和ncols
列的網格上占據index
位置。index
從左上角的 1 開始,向右遞增。index
也可以是一個二元組,指定子圖的(first
、last
)索引(從 1 開始,包括last
),例如,fig.add_subplot(3, 1, (1, 2))
生成一個跨越上 2 的子圖/3 圖。 -
一個 3 位整數。這些數字被解釋為好像分別作為三個 single-digit 整數給出,即
fig.add_subplot(235)
與fig.add_subplot(2, 3, 5)
相同。請注意,這隻能在不超過 9 個子圖的情況下使用。 -
一個
SubplotSpec
。
-
- projection {無,'aitoff', 'hammer', 'lambert', 'mollweide', 'polar', 'rectilinear',str},可選
-
子圖的投影類型 (
Axes
)。str
是自定義投影的名稱,請參閱projections
。默認無導致 'rectilinear' 投影。 - polar 布爾值,默認值:假
-
如果為真,則相當於投影='polar'。
- sharex, sharey
Axes
,可選 -
與 sharex 和/或 sharey 共享 x 或 y
axis
。該軸將具有與共享軸的軸相同的限製、刻度和比例。 - label str
-
返回軸的標簽。
- *args int, (int, int,
- 返回:
Axes
-
子圖的軸。返回的 Axes 實際上可以是子類的實例,例如極坐標投影的
projections.polar.PolarAxes
。
- 其他參數:
- **kwargs
-
此方法還采用返回軸基類的關鍵字參數;除了
figure
參數。直線基類Axes
的關鍵字參數可以在下表中找到,但如果使用另一個投影,也可能存在其他關鍵字參數。屬性
說明
{'box', 'datalim'}
一個過濾器函數,它接受一個 (m, n, 3) 浮點數組和一個 dpi 值,並返回一個 (m, n, 3) 數組和距圖像左下角的兩個偏移量
標量或無
(浮點數、浮點數)或 {'C'、'SW'、'S'、'SE'、'E'、'NE'、...}
bool
{'auto', 'equal'} 或浮點數
bool
unknown
unknown
可調用[[軸,渲染器],Bbox]
布爾或'line'
浮點數或無
BboxBase
或無bool
補丁或(路徑,變換)或無
facecolor
或 fccolor
bool
str
bool
object
bool
bool
unknown
None 或 bool 或 float 或可調用
[左、下、寬、高]或
Bbox
浮點數或無
bool
(比例:浮點數,長度:浮點數,隨機性:浮點數)
布爾或無
unknown
str
str
bool
(下:浮點數,上:浮點數)
str
(左:浮點數,右:浮點數)
浮點數大於 -0.5
unknown
unknown
unknown
(下:浮點數,上:浮點數)
str
(底部:浮點數,頂部:浮點數)
浮點數大於 -0.5
unknown
unknown
unknown
float
注意
創建新的軸將刪除與其共享邊界之外的任何先前存在的軸:
import matplotlib.pyplot as plt # plot a line, implicitly creating a subplot(111) plt.plot([1, 2, 3]) # now create a subplot which represents the top plot of a grid # with 2 rows and 1 column. Since this subplot will overlap the # first, the plot (and its axes) previously created, will be removed plt.subplot(211)
如果您不希望出現這種情況,請改用
Figure.add_subplot
方法或pyplot.axes
函數。如果沒有傳遞
kwargs
並且在args
指定的位置存在軸,則將返回該軸,而不是創建新的軸。如果通過
kwargs
並且在args
指定的位置存在Axes,則投影類型相同,且kwargs
與現有Axes匹配,則返回現有Axes。否則,將使用指定的參數創建一個新軸。我們保存了對kwargs
的引用,用於此比較。如果kwargs
中的任何值是可變的,我們將不會檢測到它們發生突變的情況。在這些情況下,我們建議使用Figure.add_subplot
和顯式 Axes API 而不是隱式 pyplot API。例子
plt.subplot(221) # equivalent but more general ax1 = plt.subplot(2, 2, 1) # add a subplot with no frame ax2 = plt.subplot(222, frameon=False) # add a polar subplot plt.subplot(223, projection='polar') # add a red subplot that shares the x-axis with ax1 plt.subplot(224, sharex=ax1, facecolor='red') # delete ax2 from the figure plt.delaxes(ax2) # add ax2 to the figure again plt.subplot(ax2) # make the first axes "current" again plt.subplot(221)
用法
matplotlib.pyplot.subplot(*args, **kwargs)
相關用法
- Python matplotlib subplots用法及代碼示例
- Python matplotlib subplot2grid用法及代碼示例
- Python matplotlib silent_list用法及代碼示例
- Python matplotlib step用法及代碼示例
- Python matplotlib select_matching_signature用法及代碼示例
- Python matplotlib semilogx用法及代碼示例
- Python matplotlib semilogy用法及代碼示例
- Python matplotlib savefig用法及代碼示例
- 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 InsetPosition用法及代碼示例
- Python matplotlib ToolManager.toolmanager_disconnect用法及代碼示例
- Python matplotlib Figure.set_size_inches用法及代碼示例
- Python matplotlib figlegend用法及代碼示例
- Python matplotlib Axes.step用法及代碼示例
- Python matplotlib Axes.contour用法及代碼示例
- Python matplotlib LassoSelector用法及代碼示例
- Python matplotlib BrokenBarHCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.plot用法及代碼示例
- Python matplotlib Axes.semilogx用法及代碼示例
注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.pyplot.subplot。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。