答案 0 :(得分:2)
这是一种可能的方法,使用ax.set_yticklabels
:
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(0)
x = np.arange(8)
y1 = np.random.rand(4)
y2 = np.random.rand(4)
fig, ax = plt.subplots()
ax.barh(x[::2], y1, color="C3")
ax.barh(x[1::2], y2, color="C0")
t = range(len(x))
ax.set_yticks(t)
t[0::2] = ["another tick"]*(len(x)/2)
t[1::2] = ["tick {}".format(i+1) for i in range((len(x)/2))]
ax.set_yticklabels(t)
plt.tight_layout()
plt.show()