使用seaborn中的catplot()同時繪制多個圖
catplot(x=None, y=None, hue=None, data=None, row=None, col=None, col_wrap=None, estimator=<function mean at 0x000002865D33E8C8>, ci=95, n_boot=1000, units=None, order=None, hue_order=None, row_order=None, col_order=None, kind='strip', height=5, aspect=1, orient=None, color=None, palette=None, legend=True, legend_out=True, sharex=True, sharey=True, margin_titles=False, facet_kws=None, **kwargs)
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset("tips")
sns.catplot(x="day", y="total_bill", hue="smoker",
col="time", aspect=.6, kind="swarm",
data=tips, legend=True, legend_out=False)
#ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper left')
plt.show()
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
titanic = sns.load_dataset("titanic")
g = sns.catplot(x="fare", y="survived", row="class",
kind="box", orient="h", height=1.5, aspect=4,
data=titanic.query("fare > 0"))
g.set(xscale="log")
plt.show()
可以通過row,col參數指定要根據什麼屬性進行分行(列)顯示
orient參數可以設定朝向,這通常要結合橫縱坐标軸考慮,可以設為'v'或'h'