如何在下面的例子中给出标签“a”,“b”,“c”个别颜色(例如“a”为绿色,“b”为蓝色,“c”为红色)?
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
p = plt.boxplot(np.random.normal(size=(10,3)))
ax.set_xticklabels(list("abc"))
plt.show()
答案 0 :(得分:13)
代码:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
p = plt.boxplot(np.random.normal(size=(10,3)))
ax.set_xticklabels(list("abc"))
[t.set_color(i) for (i,t) in
zip(['red','green','blue'],ax.xaxis.get_ticklabels())]
plt.show()
给我: