如何创建一个包含 2 个 seaborn 地块(子图)的地块
\n\n如何将 2 个seaborn 地块合并为 1 个?
\n\nplt.figure(figsize = (12, 6))\nax = sns.scatterplot(x = model1.fittedvalues, y = model1.resid)\nplt.grid()\nax.axhline(y=0, color=\'r\', linewidth=4) \nax.set_xlabel("vysv\xc4\x9btlovan\xc3\xa1 prom\xc4\x9bnn\xc3\xa1");\nax.set_ylabel("residua");\n\n\nplt.figure(figsize = (12, 6))\nax = sns.distplot(a = model1.resid, bins = 40, norm_hist=True,)\nplt.grid()\nax.set_title("Histogram rezidu\xc3\xad", fontsize = 25);\n\nRun Code Online (Sandbox Code Playgroud)\n
您可以按照您喜欢的方式创建子图(使用plt.subplots()、fig.add_subplot()、GridSpec,您可以命名它),然后使用对轴的引用传递给seaborn函数ax=<your axes reference>
fig, (ax1, ax2) = plt.subplots(1,2, figsize = (24, 6))\nsns.scatterplot(x = model1.fittedvalues, y = model1.resid, ax=ax1)\nax1.grid()\nax1.axhline(y=0, color=\'r\', linewidth=4) \nax1.set_xlabel("vysv\xc4\x9btlovan\xc3\xa1 prom\xc4\x9bnn\xc3\xa1");\nax1.set_ylabel("residua");\n\nsns.distplot(a = model1.resid, bins = 40, norm_hist=True, ax=ax2)\nax2.grid()\nax2.set_title("Histogram rezidu\xc3\xad", fontsize = 25);\nRun Code Online (Sandbox Code Playgroud)\n