1. 程式人生 > >seaborn.FacetGrid()的使用

seaborn.FacetGrid()的使用

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)

用於繪製條件關係的多圖網格。

__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物件。

此類將資料集對映到排列在行和列網格中的多個軸上,這些行對應於資料集中的變數級別。它產生的圖通常被稱為“格子”,“格子”或“小多”圖形。
它還可以用色調引數表示第三個變數的級別,該引數繪製不同顏色的不同資料子集。這使用顏色來解析第三維上的元素,但僅在彼此之上繪製子集,並且不會像接受色調的軸級函式那樣為特定視覺化定製hue引數。
當使用從資料集推斷語義對映的seaborn函式時,必須注意在各個方面之間同步這些對映。在大多數情況下,使用圖形級函式(例如relplot()或catplot())比直接使用FacetGrid更好。
基本流程是使用資料集和用於構造網格的變數初始化FacetGrid物件。然後,通過呼叫FacetGrid.map()或FacetGrid.map_dataframe(),可以將一個或多個繪圖函式應用於每個子集。最後,可以使用其他方法調整繪圖,以執行更改軸標籤,使用不同刻度或新增圖例等操作。

Parameters:

data : DataFrame

Tidy (“long-form”) dataframe where each column is a variable and each row is an observation.

row, col, hue : strings

Variables that define subsets of the data, which will be drawn on separate facets in the grid. See the *_order parameters to control the order of levels of this variable.

col_wrap : int, optional

“Wrap” the column variable at this width, so that the column facets span multiple rows. Incompatible with a row facet.

share{x,y} : bool, ‘col’, or ‘row’ optional

If true, the facets will share y axes across columns and/or x axes across rows.

height : scalar, optional

Height (in inches) of each facet. See also: aspect.

aspect : scalar, optional

Aspect ratio of each facet, so that aspect * height gives the width of each facet in inches.

palette : palette name, list, or dict, optional

Colors to use for the different levels of the hue variable. Should be something that can be interpreted by color_palette(), or a dictionary mapping hue levels to matplotlib colors.

{row,col,hue}_order : lists, optional

Order for the levels of the faceting variables. By default, this will be the order that the levels appear in data or, if the variables are pandas categoricals, the category order.

hue_kws : dictionary of param -> list of values mapping

Other keyword arguments to insert into the plotting call to let other plot attributes vary across levels of the hue variable (e.g. the markers in a scatterplot).

legend_out : bool, optional

If True, the figure size will be extended, and the legend will be drawn outside the plot on the center right.

despine : boolean, optional

Remove the top and right spines from the plots.

margin_titles : bool, optional

If True, the titles for the row variable are drawn to the right of the last column. This option is experimental and may not work in all cases.

{x, y}lim: tuples, optional

Limits for each of the axes on each facet (only relevant when share{x, y} is True.

subplot_kws : dict, optional

Dictionary of keyword arguments passed to matplotlib subplot(s) methods.

gridspec_kws : dict, optional

Dictionary of keyword arguments passed to matplotlib’s gridspec module (via plt.subplots). Requires matplotlib >= 1.4 and is ignored if col_wrap is not None.