为什么我所有的海生情节都融为一个情节?

2024-09-30 12:26:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要8个单独的图表。有没有一种方法不使用#%%并单击8次就可以做到这一点

我这样做

Nplot130317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", hue_norm=(0,130), data=Ndata130317, s=2, linewidth=0) 
Nplot210317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata210317, s=2, linewidth=0)
Nplot290317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata290317, s=2, linewidth=0)
Nplot060417 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata060417, s=2, linewidth=0)
Iplot130317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata130317_2, s=10, linewidth=0)
Iplot210317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata210317_2, s=10, linewidth=0)
Iplot290317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata290317_2, s=10, linewidth=0)
Iplot060417 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata060417_2, s=10, linewidth=0)

这种情况发生了:

Plot


Tags: 方法normdatatime图表huespeedsns
1条回答
网友
1楼 · 发布于 2024-09-30 12:26:12

一个选项是创建一组轴/子图,并为每个对seaborn.scatterplot的调用指定ax参数。根据documentation

ax : matplotlib Axes, optional
Axes object to draw the plot onto, otherwise uses the current Axes.

在问题代码中,这可以按如下方式进行

fig, axs = plt.subplots(2, 4, figsize=(16,6))
Nplot130317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata130317, ax=axs[0,0]) 
Nplot210317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata210317, ax=axs[0,1])
Nplot290317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata290317, ax=axs[0,2])
Nplot060417 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Ndata060417, ax=axs[0,3])
Iplot130317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata130317_2, ax=axs[1,0])
Iplot210317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata210317_2, ax=axs[1,1])
Iplot290317 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata290317_2, ax=axs[1,2])
Iplot060417 = sns.scatterplot(x="NewID", y="Time", hue="Speed", data=Idata060417_2, ax=axs[1,3])

相关问题 更多 >

    热门问题