python - is there a way to add 2 yticks and 2 bars in one matplotlib plot? -
here possible way, using ax.set_yticklabels
:
import matplotlib.pyplot plt import numpy 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) in range((len(x)/2))] ax.set_yticklabels(t) plt.tight_layout() plt.show()
Comments
Post a Comment