【问题标题】:Xticks gets accumulated in a small regionXticks 在一个小区域内积累
【发布时间】:2020-09-03 18:06:12
【问题描述】:

我正在尝试绘制线图并在图中使用自定义 xticks。这是我使用的代码:

sns.set_style("darkgrid")
sns.lineplot(y = mean_train_score, x = alpha, label = "Train")
sns.scatterplot(y = mean_train_score, x = alpha, label = "Train")

sns.lineplot(y = mean_val_score, x = alpha, label = "Validation")
sns.scatterplot(y = mean_val_score, x = alpha, label = "Validation")

plt.title("Hyperparameter vs AUC plot")
plt.xlabel("Alpha")
plt.ylabel("AUC")
plt.xticks(np.arange(100), np.arange(0,100,10))
plt.legend()
plt.show()

这是它生成的情节:

这是原图

我认为这是 plt.xticks 部分的问题。请帮忙:)。

【问题讨论】:

    标签: python-3.x matplotlib plot seaborn xticks


    【解决方案1】:

    您的代码现在的运行方式是,所有 x-ticks 都位于 (0,0) 处,因为数组的长度不同。通过这样做,我能够让 xticks 工作

    plt.xticks(np.arange(100), [x if x%10==0 else None for x in np.arange(100)]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-20
      • 2016-08-28
      • 2020-12-26
      • 1970-01-01
      • 2021-10-01
      • 2012-05-13
      • 2016-06-03
      • 1970-01-01
      相关资源
      最近更新 更多