seaborn.objects.Plot.facet#

Plot.facet(col=None, row=None, order=None, wrap=None)#

使用資料的條件子集產生子圖。

參數:
col, row資料向量或識別符

用於定義網格欄和/或列的子集的變數。可以是傳遞到建構函式中的全域資料來源的參考。

order字串列表,或帶有維度鍵的字典

定義分面變數的順序。

wrap整數

當僅使用 colrow 時,將子圖以二維網格形式包裝,在分面維度上包含這麼多的子圖。

範例

指定一個分面變數將建立多個子圖,並在每個子圖上繪製資料的子集

p = so.Plot(penguins, "bill_length_mm", "bill_depth_mm").add(so.Dots())
p.facet("species")
../_images/objects.Plot.facet_2_0.png

可以定義多個分面變數以建立二維網格

p.facet("species", "sex")
../_images/objects.Plot.facet_4_0.png

分面變數可以作為對全域繪圖資料的參考或作為向量提供

p.facet(penguins["island"])
../_images/objects.Plot.facet_6_0.png

對於單個分面變數,透過將層級列表傳遞給 order 來排列分面或限制為子集

p.facet("species", order=["Gentoo", "Adelie"])
../_images/objects.Plot.facet_8_0.png

對於多個變數,將 order 作為字典傳遞

p.facet("species", "sex", order={"col": ["Gentoo", "Adelie"], "row": ["Female", "Male"]})
../_images/objects.Plot.facet_10_0.png

當分面變數有多個層級時,您可以 wrap 它以將子圖分佈在兩個維度上

p = so.Plot(diamonds, x="carat", y="price").add(so.Dots())
p.facet("color", wrap=4)
../_images/objects.Plot.facet_12_0.png

包裝僅在存在單個變數時有效,但您可以沿任一方向包裝

p.facet(row="color", wrap=2)
../_images/objects.Plot.facet_14_0.png

使用 Plot.share() 來指定是否應該以相同方式縮放分面

p.facet("clarity", wrap=3).share(x=False)
../_images/objects.Plot.facet_16_0.png

使用 Plot.label() 來調整標題

p.facet("color").label(title="{} grade".format)
../_images/objects.Plot.facet_18_0.png