2017-03-28 2 views

Antwort

2

Hier ist eine Art und Weise, mit ax.set_yticklabels:

enter image description here

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() 
Verwandte Themen