Set the color of xtick labels (America or Japan part) individually.
1.Code
example.ipynb
import matplotlib.pyplot as plt
#Drawing area settings
fig, ax = plt.subplots()
#xticklabels and yvalue settings(list)
X = ["America", "Japan"]
Y = [3, 1]
#color abbreviation is OK
X_label_colors = ['r', 'green']
plt.bar(X, Y, align="center")
#Associate Xtick labels with color(Must be equal)
[t.set_color(i) for (i, t) in zip(X_label_colors, ax.xaxis.get_ticklabels())]
plt.show()
Of the several labels, it can be used when there is a label that you want to stand out.
example2.ipynb
fig, ax = plt.subplots()
X = ["C/C++", "Python", "JavaScript"]
X_label_colors = ['black', 'red', 'black']
Y = [136, 127,110]
plt.bar(X, Y, align="center")
[t.set_color(i) for (i, t) in zip(X_label_colors, ax.xaxis.get_ticklabels())]
plt.show()
Recommended Posts