Reputation: 21343
I am plotting 8 subplots in a figure as follows:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(8,sharex="col" )
label = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
data = [0.6, 0.4, 1.3, 0.8, 0.9, 1.0, 1.6, 0.2]
plt.xlim(0,2)
for i in range(8):
axs[i].set_xlim([0, 2])
axs[i].axvline(data[i],linestyle='--')
axs[i].set_yticks(())
axs[i].set_ylabel(label[i], rotation=0, ha='right', va='center')
axs[7].tick_params(axis='x', direction='out')
plt.show()
It all works fine except there are no ticks on the x-axis. What am I doing wrong?
Upvotes: 1
Views: 636
Reputation: 39072
I am answering your question in the comments. You can hide the ticks for all axes except the last one using the following
for i in range(8):
axs[i].set_xlim([0, 2])
axs[i].axvline(data[i],linestyle='--')
axs[i].set_yticks(())
axs[i].set_ylabel(label[i], rotation=0, ha='right', va='center')
if i!=7:
axs[i].tick_params(axis='x', direction='out', length=0) # Hide the ticks for all but last axis
# axs[i].xaxis.set_tick_params(direction='out', length=0) # This is 2nd way to do
Upvotes: 2