【问题标题】:Seaborn split violin plot not splitting properlySeaborn 分裂小提琴情节未正确分裂
【发布时间】:2021-02-16 12:07:16
【问题描述】:

我正在尝试制作分裂小提琴情节,但情节在生成时从未真正分裂过。我已经尝试关注seaborn guide,但我不确定出了什么问题,因为它不会像指南中那样产生 2 色分裂小提琴。

我的 DF 看起来像这样:

       Accuracy  Train_Time Model
0  0  0.825165  170.013132  LSTM
1  1  0.849305  171.778840  LSTM
2  2  0.826628  174.107146  LSTM
3  3  0.834674  176.774985  LSTM
4  0  0.927944   18.521901   CNN
5  1  0.929042   18.595950   CNN
6  2  0.930139   18.421983   CNN
7  3  0.927213   18.329449   CNN

我的 seaborn 情节代码如下所示:

sns.set_theme(style="whitegrid")
ax = sns.violinplot(y="Accuracy", hue="Model", data=comp_df, palette="Set2", split=True)
plt.show()

【问题讨论】:

    标签: python python-3.x seaborn


    【解决方案1】:

    hue-nesting 只能用于x。在您的情况下,您需要为整个数据集创建一个具有相同值的虚拟列。

    comp_df['dummy'] = 0
    ax = sns.violinplot(y="Accuracy", x='dummy', hue="Model", data=comp_df, palette="Set2", split=True)
    

    【讨论】:

      猜你喜欢
      • 2019-05-21
      • 1970-01-01
      • 2018-05-15
      • 2018-01-15
      • 1970-01-01
      • 2019-06-23
      • 2020-12-11
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多