문제

How can I give the labels "a", "b", "c" individual colors (e.g. "a" in green, "b" in blue, "c" in red) in the example below?

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

Example of boxplot without individually colored labels.

도움이 되었습니까?

해결책

The code:

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

Gives me:

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top