seaborn.objects.Plot.facet#
- Plot.facet(col=None, row=None, order=None, wrap=None)#
使用資料的條件子集產生子圖。
- 參數:
- col, row資料向量或識別符
用於定義網格欄和/或列的子集的變數。可以是傳遞到建構函式中的全域資料來源的參考。
- order字串列表,或帶有維度鍵的字典
定義分面變數的順序。
- wrap整數
當僅使用
col
或row
時,將子圖以二維網格形式包裝,在分面維度上包含這麼多的子圖。
範例
指定一個分面變數將建立多個子圖,並在每個子圖上繪製資料的子集
p = so.Plot(penguins, "bill_length_mm", "bill_depth_mm").add(so.Dots()) p.facet("species")
可以定義多個分面變數以建立二維網格
p.facet("species", "sex")
分面變數可以作為對全域繪圖資料的參考或作為向量提供
p.facet(penguins["island"])
對於單個分面變數,透過將層級列表傳遞給
order
來排列分面或限制為子集p.facet("species", order=["Gentoo", "Adelie"])
對於多個變數,將
order
作為字典傳遞p.facet("species", "sex", order={"col": ["Gentoo", "Adelie"], "row": ["Female", "Male"]})
當分面變數有多個層級時,您可以
wrap
它以將子圖分佈在兩個維度上p = so.Plot(diamonds, x="carat", y="price").add(so.Dots()) p.facet("color", wrap=4)
包裝僅在存在單個變數時有效,但您可以沿任一方向包裝
p.facet(row="color", wrap=2)
使用
Plot.share()
來指定是否應該以相同方式縮放分面p.facet("clarity", wrap=3).share(x=False)
使用
Plot.label()
來調整標題p.facet("color").label(title="{} grade".format)