Matplotlib: color index / label

How would one Y-axis color cue and cue tags be red?

So, for example, "y-label" and values โ€‹โ€‹from 0 to 40 to be colored 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() 
+8
matplotlib colors label
source share
2 answers
  label = plt.ylabel("y-label") label.set_color("red") 

Similarly, you can get and change tick marks:

 [i.set_color("red") for i in plt.gca().get_xticklabels()] 
+15
source share

Xelabel can be colored during customization,

 ax.set_xlabel("x-label", color="red") 

To set the color of the tag label, you can use tick_params , which sets the tag labels, as well as the color of ticks.

 ax.tick_params(axis='x', colors='red') 

enter image description here

Alternatively, plt.setp can only be used to set the color of shortcuts without changing the color of the ticks.

 plt.setp(ax.get_xticklabels(), color="red") 

enter image description here

Note that to change properties along the y axis, you can replace x with y in the above.

+7
source share

All Articles