Matplotlib: axis color change

Is there a way to change the color of the axis (not ticks) in matplotlib? I looked through documents for Axes, Axis, and Artist, but no luck; there is no hint in the matplotlib gallery either. Any idea?

+32
matplotlib colors
Dec 30 '09 at 22:04
source share
3 answers

When using numbers, you can easily change the color of the spine with:

ax.spines['bottom'].set_color('#dddddd') ax.spines['top'].set_color('#dddddd') ax.spines['right'].set_color('red') ax.spines['left'].set_color('red') 

To change only ticks, use the following:

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

And to change only the labels:

 ax.yaxis.label.set_color('red') ax.xaxis.label.set_color('red') 

And finally, the name:

 ax.title.set_color('red') 
+56
Aug 21 2018-12-18T00:
source share

For the record, so I managed to get it to work:

 fig = pylab.figure() ax = fig.add_subplot(1, 1, 1) for child in ax.get_children(): if isinstance(child, matplotlib.spines.Spine): child.set_color('#dddddd') 
+16
Jan 01 '09 at 19:04
source share

You can do this by setting the default rc settings.

 import matplotlib from matplotlib import pyplot as plt matplotlib.rc('axes',edgecolor='r') plt.plot([0, 1], [0, 1]) plt.savefig('test.png') 
+7
Jan 01 '09 at 19:14
source share



All Articles