I have a double y-axis plot and I can't get the xticks labels working.
This is when I don't modify the xticks:
This is when I do:

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()
You are setting your new x tick labels onto the automatically generated xticks. You probably want to set the tick locations to the values of neruons:
ax.set_xticks(neurons)
ax.set_xticklabels(neurons)
which gives something like

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With