以科学计数法为所有刻度标签上色

时间:2018-09-10 15:16:57

标签: python matplotlib

我想给左垂直轴的刻度标签上色。但是,以下代码:

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()

无法为所有标签着色:

enter image description here

1 个答案:

答案 0 :(得分:1)

使用

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

其中both对应于主要和次要刻度线。

输出

enter image description here