简体   繁体   中英

Color all tick labels in scientific notation

I want to color the tick labels of my left vertical axis. However, the following code:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.plot([1,5,10],[1,5,10])

ax.set_xscale('log')
ax.set_yscale('log')

ax.set_xlim([1e0,1e1])
ax.set_ylim([1e0,1e1])

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

plt.savefig('test.png')
plt.show()

fails to color all lables:

在此处输入图片说明

Use

ax.tick_params(axis='y', colors='b', which='both')

where both corresponds to the major as well as the minor ticks.

Output

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM