4

Following the advice of Changing the color of the axis, ticks and labels for a plot in matplotlib I have managed to set the colour of the spine, label, numbers and ticks of my graph using:

ax.spines['left'].set_color('#FF9000')
ax.yaxis.label.set_color('#FF9000')
ax.tick_params(axis='y', colors='#FF9000')

However, when I set the axes of my graph to log scale the ticks revert to black again.

For example:

ax.set_yscale('log')
ax.spines['left'].set_color('#FF9000')
ax.yaxis.label.set_color('#FF9000')
ax.tick_params(axis='y', colors='#FF9000') <-- now only half works

This draws the numbers the colour I want (so I know the command still does something) but doesn't affect the ticks.

Is there a way to set the colour of log scaled ticks?

Community
  • 1
  • 1
Mark Jones
  • 215
  • 2
  • 8

1 Answers1

8

This works correctly on my system (runniing very close to the current git master):

You just need to add the kwarg which='both' (doc)

figure()
ax = gca()

ax.set_yscale('log')
ax.spines['left'].set_color('#FF9000')
ax.yaxis.label.set_color('#FF9000')

ax.tick_params(axis='y', colors='#FF9000', width=5, which='both')

I made the ticks thicker to make it easy to see the color.

In a log scale, the small ticks are minor ticks, and by default tick_params only changes the major ticks, you just need to tell it to do both or explicitly do each (major and minor) separately.

tacaswell
  • 84,579
  • 22
  • 210
  • 199