Matplotlib: Changing the color of an axis

When using figures, you can easily change the spine color 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')

Use the following to change only the ticks:

  • which="both" changes both the major and minor tick colors
ax.tick_params(axis="x", colors="red")
ax.tick_params(axis="y", colors="red")

And the following to change only the label:

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

And finally the title:

ax.title.set_color('red')

Leave a Comment