可以通过将标签设置在次要刻度上,然后将次要刻度宽度设置为零,以便看不到它们:import matplotlib.ticker as ticker
# Set the major and minor tick locations
ax.xaxis.set_major_locator(ticker.MultipleLocator(np.pi/4))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(np.pi/8))
# Turn off major tick labels
ax.xaxis.set_major_formatter(ticker.NullFormatter())
# Set the minor tick width to 0 so you don't see them
for tick in ax.xaxis.get_minor_ticks():
tick.tick1line.set_markersize(0)
tick.tick2line.set_markersize(0)
tick.label1.set_horizontalalignment('center')
# Set the names of your ticks, with blank spaces for the major ticks
ax.set_xticklabels(['','','Seg 1','','Seg 2','','Seg 3','','Seg 4','','Seg 5','','Seg 6','','Seg 7','','Seg 8'],minor=True)