<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # seaborn.FacetGrid > 譯者:[hyuuo](https://github.com/hyuuo) ```py class seaborn.FacetGrid(data, row=None, col=None, hue=None, col_wrap=None, sharex=True, sharey=True, height=3, aspect=1, palette=None, row_order=None, col_order=None, hue_order=None, hue_kws=None, dropna=True, legend_out=True, despine=True, margin_titles=False, xlim=None, ylim=None, subplot_kws=None, gridspec_kws=None, size=None) ``` 用于繪制條件關系的多圖網格。 ```py __init__(data, row=None, col=None, hue=None, col_wrap=None, sharex=True, sharey=True, height=3, aspect=1, palette=None, row_order=None, col_order=None, hue_order=None, hue_kws=None, dropna=True, legend_out=True, despine=True, margin_titles=False, xlim=None, ylim=None, subplot_kws=None, gridspec_kws=None, size=None) ``` 初始化 matplotlib 畫布和 FacetGrid 對象。 該類將數據集映射到由行和列組成的網格中的多個軸上,這些軸與數據集中變量的級別對應。它產生的圖通常被稱為“lattice”,“trellis”或“small-multiple”圖形。 它還可以用`hue`參數表示第三個變量的級別,該參數繪制不同顏色的不同數據子集。它使用顏色來解析第三維度上的元素,但是只繪制相互重疊的子集,并且不會像接受“hue”的坐標軸級函數那樣為特定的可視化定制“hue”參數。 當使用從數據集推斷語義映射的 seaborn 函數時,必須注意在各個方面之間同步這些映射。在大多數情況下,使用圖形級函數(例如[`relplot()`](seaborn.relplot.html#seaborn.relplot "seaborn.relplot")或[`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot"))比直接使用[`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")更好。 基本工作流程是使用數據集和用于構造網格的變量初始化 FacetGrid 對象。然后,通過調用[`FacetGrid.map()`](seaborn.FacetGrid.map.html#seaborn.FacetGrid.map "seaborn.FacetGrid.map")或[`FacetGrid.map_dataframe()`](seaborn.FacetGrid.map_dataframe.html#seaborn.FacetGrid.map_dataframe "seaborn.FacetGrid.map_dataframe"),可以將一個或多個繪圖函數應用于每個子集。最后,可以使用其他方法調整繪圖,以執行更改軸標簽、使用不同刻度或添加圖例等操作。有關詳細信息,請參閱下面的詳細代碼示例。 更多相關信息請參閱[`教程`](http://seaborn.pydata.org/tutorial/axis_grids.html#grid-tutorial)。 參數:`data`:DataFrame 數據。 > 整潔的(“長形式”)dataframe 數據,其中每一列是一個變量,每一行是一個觀察實例。 `row, col, hue`:字符串。 > 定義數據子集的變量,這些變量將在網格的不同方面繪制。請參閱`*_order`參數以控制此變量的級別順序。 `col_wrap`:整形數值,可選參數。 > 以此參數值來限制網格的列維度,以便列面跨越多行。與`row`面不兼容。 `share{x,y}`:布爾值,'col' 或 'row'可選 > 如果為 true,則跨列共享 y 軸或者跨行共享 x 軸。 `height`:標量,可選參數。 > 每個圖片的高度設定(以英寸為單位)。另見:*aspect* `aspect`:標量,可選參數。 > 每個圖片的縱橫比,因此 aspect * height 給出每個圖片的寬度,單位為英寸。 `palette`:調色板名稱,列表或字典,可選參數。 > 用于色調變量的不同級別的顏色。應為[`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette")可以解釋的參數,或者是將色調級別映射到 matplotlib 顏色的字典。 `{row,col,hue}_order`:列表,可選參數。 > 對所給命令級別進行排序。默認情況下,這將是在數據中顯示的級別,或者,如果變量是 pandas 分類,則為類別順序。 `hue_kws`:參數-列表值的映射字典 > 插入到繪圖調用中的其他關鍵字參數,使得其他繪圖屬性在色調變量的級別上有所不同(例如散點圖中的標記)。 `legend_out`:布爾值,可選參數。 > 如果為 True,則圖形尺寸將被擴展,圖例將繪制在中間右側的圖形之外。 `despine`:布爾值,可選參數。 > 從圖中移除頂部和右側邊緣框架。 `margin_titles`:布爾值,可選參數。 > 如果為 True,則行變量的標題將繪制在最后一列的右側。此選項是實驗性的,可能無法在所有情況下使用。 `{x, y}lim`:元組,可選參數。 > 每個圖片上每個軸的限制(僅當 share {x,y}為 True 時才相關)。 `subplot_kws`:字典,可選參數。 > 傳遞給 matplotlib subplot(s)方法的關鍵字參數字典。 `gridspec_kws`:字典,可選參數。 > 傳遞給 matplotlib 的`gridspec`模塊(通過`plt.subplots`)的關鍵字參數字典。需要 matplotlib> = 1.4,如果`col_wrap`不是`None`,則忽略它。 **另請參見** 用于繪制成對關系的子圖網格。 [`relplot`](#seaborn.relplot "seaborn.relplot") 結合關系圖和[`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid")。 [`catplot`](#seaborn.catplot "seaborn.catplot") 結合分類圖和[`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid")。 [`lmplot`](#seaborn.lmplot "seaborn.lmplot") 結合回歸圖和[`FacetGrid`](#seaborn.FacetGrid "seaborn.FacetGrid")。 范例 使用 tips 數據集初始化 2x2 網格圖: ```py >>> import seaborn as sns; sns.set(style="ticks", color_codes=True) >>> tips = sns.load_dataset("tips") >>> g = sns.FacetGrid(tips, col="time", row="smoker") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-1.png](https://img.kancloud.cn/b0/59/b05954f6f0ec40d4741652e30061d75d_540x540.jpg) 在每個子圖繪制一個單變量圖: ```py >>> import matplotlib.pyplot as plt >>> g = sns.FacetGrid(tips, col="time", row="smoker") >>> g = g.map(plt.hist, "total_bill") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-2.png](https://img.kancloud.cn/f9/41/f941720f3721457800af80aa037f23bf_540x540.jpg) (注意,沒有必要重新捕獲返回的變量;它是相同的對象,但在示例中這樣做使得處理 doctests 更加方便)。 將其他關鍵字參數傳遞給映射函數: ```py >>> import numpy as np >>> bins = np.arange(0, 65, 5) >>> g = sns.FacetGrid(tips, col="time", row="smoker") >>> g = g.map(plt.hist, "total_bill", bins=bins, color="r") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-3.png](https://img.kancloud.cn/d4/80/d480254c7a8cf27e331b8fecec06f7ab_540x540.jpg) 在每個子圖繪制一個雙變量函數: ```py >>> g = sns.FacetGrid(tips, col="time", row="smoker") >>> g = g.map(plt.scatter, "total_bill", "tip", edgecolor="w") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-4.png](https://img.kancloud.cn/2d/65/2d659af7f593c5726ee739e170d5d6a2_540x540.jpg) 將其中一個變量分配給繪圖元素的顏色: ```py >>> g = sns.FacetGrid(tips, col="time", hue="smoker") >>> g = (g.map(plt.scatter, "total_bill", "tip", edgecolor="w") ... .add_legend()) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-5.png](https://img.kancloud.cn/a2/62/a262b3c800729cf17d0536b691573ea9_613x270.jpg) 更改每個子圖的高度和縱橫比: ```py >>> g = sns.FacetGrid(tips, col="day", height=4, aspect=.5) >>> g = g.map(plt.hist, "total_bill", bins=bins) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-6.png](https://img.kancloud.cn/5d/10/5d10b23b278fac627c3f0d552d62adff_720x360.jpg) 指定繪圖元素的順序: ```py >>> g = sns.FacetGrid(tips, col="smoker", col_order=["Yes", "No"]) >>> g = g.map(plt.hist, "total_bill", bins=bins, color="m") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-7.png](https://img.kancloud.cn/e8/92/e892b229b53609661ec9e6d3bde0f83b_540x270.jpg) 使用不同的調色板: ```py >>> kws = dict(s=50, linewidth=.5, edgecolor="w") >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette="Set1", ... hue_order=["Dinner", "Lunch"]) >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws) ... .add_legend()) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-8.png](https://img.kancloud.cn/6f/e8/6fe842e62d8dd4ccbfb5b839590049db_630x270.jpg) 使用字典將色調級別映射到顏色: ```py >>> pal = dict(Lunch="seagreen", Dinner="gray") >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal, ... hue_order=["Dinner", "Lunch"]) >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws) ... .add_legend()) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-9.png](https://img.kancloud.cn/1d/93/1d9347d2e2a07127c15210c9a253bf50_630x270.jpg) 另外,為色調級別使用不同的標記: ```py >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal, ... hue_order=["Dinner", "Lunch"], ... hue_kws=dict(marker=["^", "v"])) >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws) ... .add_legend()) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-10.png](https://img.kancloud.cn/f3/df/f3df0e458117ef8627c6cadd2ef70465_630x270.jpg) 將包含多個級別的列變量“換行”到行中: ```py >>> att = sns.load_dataset("attention") >>> g = sns.FacetGrid(att, col="subject", col_wrap=5, height=1.5) >>> g = g.map(plt.plot, "solutions", "score", marker=".") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-11.png](https://img.kancloud.cn/ee/73/ee732f4175f3cdc3304f73ae6e02f8d2_675x540.jpg) 定義一個自定義雙變量函數來映射到網格: ```py >>> from scipy import stats >>> def qqplot(x, y, **kwargs): ... _, xr = stats.probplot(x, fit=False) ... _, yr = stats.probplot(y, fit=False) ... plt.scatter(xr, yr, **kwargs) >>> g = sns.FacetGrid(tips, col="smoker", hue="sex") >>> g = (g.map(qqplot, "total_bill", "tip", **kws) ... .add_legend()) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-12.png](https://img.kancloud.cn/5d/51/5d5165f9c6f6f613a061f07005a2765d_635x270.jpg) 定義一個使用`DataFrame`對象的自定義函數,并接受列名作為位置變量: ```py >>> import pandas as pd >>> df = pd.DataFrame( ... data=np.random.randn(90, 4), ... columns=pd.Series(list("ABCD"), name="walk"), ... index=pd.date_range("2015-01-01", "2015-03-31", ... name="date")) >>> df = df.cumsum(axis=0).stack().reset_index(name="val") >>> def dateplot(x, y, **kwargs): ... ax = plt.gca() ... data = kwargs.pop("data") ... data.plot(x=x, y=y, ax=ax, grid=False, **kwargs) >>> g = sns.FacetGrid(df, col="walk", col_wrap=2, height=3.5) >>> g = g.map_dataframe(dateplot, "date", "val") ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-13.png](https://img.kancloud.cn/5d/ca/5dca3a51c82270ec9fc6e213032950f6_630x630.jpg) 繪圖后使用不同的軸標簽: ```py >>> g = sns.FacetGrid(tips, col="smoker", row="sex") >>> g = (g.map(plt.scatter, "total_bill", "tip", color="g", **kws) ... .set_axis_labels("Total bill (US Dollars)", "Tip")) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-14.png](https://img.kancloud.cn/12/bb/12bb14f55c335739d411697ba6e6a020_540x540.jpg) 設置每個子圖共享的其他屬性: ```py >>> g = sns.FacetGrid(tips, col="smoker", row="sex") >>> g = (g.map(plt.scatter, "total_bill", "tip", color="r", **kws) ... .set(xlim=(0, 60), ylim=(0, 12), ... xticks=[10, 30, 50], yticks=[2, 6, 10])) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-15.png](https://img.kancloud.cn/21/47/2147b8bc62b1079e03cd698d4a183287_540x540.jpg) 為子圖標題使用不同的模板: ```py >>> g = sns.FacetGrid(tips, col="size", col_wrap=3) >>> g = (g.map(plt.hist, "tip", bins=np.arange(0, 13), color="c") ... .set_titles("{col_name} diners")) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-16.png](https://img.kancloud.cn/57/85/5785aef5cb78b6f47806c3b96ddcc548_810x540.jpg) 收緊每個子圖: ```py >>> g = sns.FacetGrid(tips, col="smoker", row="sex", ... margin_titles=True) >>> g = (g.map(plt.scatter, "total_bill", "tip", color="m", **kws) ... .set(xlim=(0, 60), ylim=(0, 12), ... xticks=[10, 30, 50], yticks=[2, 6, 10]) ... .fig.subplots_adjust(wspace=.05, hspace=.05)) ``` ![http://seaborn.pydata.org/_images/seaborn-FacetGrid-17.png](https://img.kancloud.cn/0a/f2/0af2595fc792e19cf921efc15e9ae5f0_540x540.jpg) 方法 | [`__init__`](#seaborn.FacetGrid.__init__ "seaborn.FacetGrid.__init__")(data[, row, col, hue, col_wrap, …]) | 初始化 matplotlib 畫布和 FacetGrid 對象。 | | `add_legend`([legend_data, title, label_order]) | 繪制一個圖例,可能將其放在軸外并調整圖形大小。| | `despine`(\**kwargs) | 從子圖中移除軸的邊緣框架。 | | `facet_axis`(row_i, col_j) | 使這些索引識別的軸處于活動狀態并返回。 | | `facet_data`() | 用于每個子圖的名稱索引和數據子集的生成器。 | | [`map`](seaborn.FacetGrid.map.html#seaborn.FacetGrid.map "seaborn.FacetGrid.map")(func, *args, \**kwargs) | 將繪圖功能應用于每個子圖的數據子集。 | | [`map_dataframe`](seaborn.FacetGrid.map_dataframe.html#seaborn.FacetGrid.map_dataframe "seaborn.FacetGrid.map_dataframe")(func, *args, \**kwargs) | 像`.map`一樣,但是將 args 作為字符串傳遞并在 kwargs 中插入數據。 | | `savefig`(*args, \**kwargs) | 保存圖片。 | | `set`(\**kwargs) | 在每個子圖集坐標軸上設置屬性。| | `set_axis_labels`([x_var, y_var]) | 在網格的左列和底行設置軸標簽。 | | `set_titles`([template, row_template, …]) | 在每個子圖上方或網格邊緣繪制標題。 | | `set_xlabels`([label]) | 在網格的底行標記 x 軸。 | | `set_xticklabels`([labels, step]) | 在網格的底行設置 x 軸刻度標簽。 | | `set_ylabels`([label]) | 在網格的左列標記 y 軸。 | | `set_yticklabels`([labels]) | 在網格的左列上設置 y 軸刻度標簽。 | 屬性 | `ax` | 輕松訪問單個坐標軸。 |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看