ax.plot(x)
plt.ylabel('Some label')
plt.tight_layout()
make_invisible = True
if make_invisible:
    xticks = ax.xaxis.get_major_ticks()
xticks[0].label1.set_visible(False)
xticks[-1].label1.set_visible(False)
plt.show()
Matplotlib - hiding specific ticks on x-axis