Search code examples
matplotlibcolorslabelxtickstext-coloring

Coloring axis/tick labels


How would one color y-axis label and tick labels in red?

So for example the "y-label" and values 0 through 40, to be colored in red. sample_image

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)

fig = plt.figure()
ax = plt.subplot(111)
ax.set_ylabel("y-label")

for i in xrange(5):
    ax.plot(x, i * x, label='$y = %ix$' % i)

ax.legend()

plt.show()

Solution

  •   label = plt.ylabel("y-label")
      label.set_color("red")
    

    similarly, you can obtain and modify the tick labels:

    [i.set_color("red") for i in plt.gca().get_xticklabels()]