【问题标题】:How come all my seaborn plots melt into one plot?为什么我所有的海产地块都融为一个地块?
【发布时间】:2020-07-08 07:44:18
【问题描述】:

我需要 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)

这会发生:

【问题讨论】:

  • 在每个sns.scatterplot()之后添加plt.show()?

标签: python plot seaborn legend spyder


【解决方案1】:

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

axma​​tplotlib 轴,可选
用于绘制绘图的 Axes 对象,否则使用当前 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])

【讨论】:

    猜你喜欢
    • 2023-03-26
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 2017-05-30
    相关资源
    最近更新 更多