先看看一個例子
#類別變量的每個類別頻數可視化 def count_plot(x, **kwargs): sns.countplot(x=x) x=plt.xticks(rotation=90) f = pd.melt(train, value_vars=['Sex','Embarked']) g = sns.FacetGrid(f, col="variable", col_wrap=2, sharex=False, sharey=False, size=5) g = g.map(count_plot, "value")

我的理解是繪制多個變量(但是數據量太多就不建議使用該方法,因為該類接受的對象是長數據,長數據需要使用到melt,數據量太大會很耗時),但是又不寫循環時,可以使用sns.FacetGrid(),map里面可以使用你自已定義的函數,或者是sns、plt等
首先FacetGrid是seaborn庫中的一個類,我們在初始化這個類時只需要給它傳一個DataFrame的數據集即可。實例化這個類以后,我么就可以直接使用這個對象的方法繪制需要的圖形
sns.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)
主要的參數
data:處理后的(“長格式”)dataframe數據
row, col, hue : strings 也就是行列,分組
col_wrap : int,畫布可以分為多少列
看一些有哪些屬性方法
pc.obj_info(sns.FacetGrid)
ObjInfo object of :
    函數/方法:['add_legend', 'despine', 'facet_axis', 'facet_data', 'map', 'map_dataframe', 'savefig', 'set', 'set_axis_labels', 'set_titles', 'set_xlabels', 'set_xticklabels', 'set_ylabels', 'set_yticklabels']
    屬性:['ax'] 
        我們主要看map,map接受畫圖方法(自定義或者sns自帶等),接受需要畫圖的變量,可以有1個變量或者2個,2個就是x軸和y軸
想要看更詳細的信息,請移步:https://blog.csdn.net/weixin_42398658/article/details/82960379
