gpt4 book ai didi

python - Matplotlib set_xticklabels 未对齐

转载 作者:行者123 更新时间:2023-12-01 09:45:56 26 4
gpt4 key购买 nike

我有一个双 y 轴图,我无法让 xticks 标签工作。
这是我不修改 xticks 的时候: enter image description here这是我做的时候: enter image description here

neurons = [4, 8, 16, 32, 64, 128]
fig, ax = plt.subplots(figsize=(13,7))
ax2 = ax.twinx()
# adding the plots
ax.grid(False)
ax2.grid(False)
ax.set_xticklabels(neurons)
ax.set_yticklabels(np.arange(250, 2500,250),fontsize=14)
ax2.set_yticklabels(np.arange(0, 120,20),fontsize=14)
ax.set_ylabel('Training time [s]', fontsize=18)
ax2.set_ylabel('Model avg accuracy [%]', fontsize=18)
ax.set_xlabel('Number of neurons', fontsize=18)
ax2.legend(fontsize=15)
plt.show()

最佳答案

您正在将新的 x 刻度标签设置到自动生成的 xtick 上。您可能希望将刻度位置设置为 neruons 的值:

ax.set_xticks(neurons)
ax.set_xticklabels(neurons)

它给出了类似的东西

enter image description here

关于python - Matplotlib set_xticklabels 未对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48705122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com