用科学记数法为所有刻度标签着色

问题描述 投票:0回答:1

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

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

python matplotlib
1个回答
1
投票

使用

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

其中both对应主要和次要蜱。

产量

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.