为什么我所有的 seaborn 地块都融入了一个地块?
How come all my seaborn plots melt into one plot?
我需要 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)
发生这种情况:
一个选项是创建一组 axes/subplots 并为每次调用 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])
我需要 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)
发生这种情况:
一个选项是创建一组 axes/subplots 并为每次调用 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])