Matplotlib:non 绘制对数时的对数标签
Matplotlib:non logarithmic labels when plotting logarithm
我正在绘制直方图,在绘制之前取数量的对数,(而不是为我的图选择对数刻度)并且在 x 轴上的刻度标签中我显然得到了对数。
我希望标签显示科学记数法:换句话说,例如,我想要 10^3 而不是 3。
有什么办法吗?我看到了其他问题,比如Matplotlib - logarithmic scale, but require non-logarithmic labels,但这不是一回事,我没有使用ax.set_xscale('log')
。
这是我的一行代码:
ax[0, 0].hist(np.log10(bh_100[:, 0]),bins=15, ls='dashed', color= 'b', log=True, label = 'Bh-bh')
您可以随时使用 set_xticklabels
根据需要设置标签
例如,您可以这样做:
ax.set_xticklabels(['10^{%d}'%i for i in range(5)])
或 LaTeX 风格:
ax.set_xticklabels(['^{%d}$'%i for i in range(5)])
我正在绘制直方图,在绘制之前取数量的对数,(而不是为我的图选择对数刻度)并且在 x 轴上的刻度标签中我显然得到了对数。 我希望标签显示科学记数法:换句话说,例如,我想要 10^3 而不是 3。
有什么办法吗?我看到了其他问题,比如Matplotlib - logarithmic scale, but require non-logarithmic labels,但这不是一回事,我没有使用ax.set_xscale('log')
。
这是我的一行代码:
ax[0, 0].hist(np.log10(bh_100[:, 0]),bins=15, ls='dashed', color= 'b', log=True, label = 'Bh-bh')
您可以随时使用 set_xticklabels
根据需要设置标签
例如,您可以这样做:
ax.set_xticklabels(['10^{%d}'%i for i in range(5)])
或 LaTeX 风格:
ax.set_xticklabels(['^{%d}$'%i for i in range(5)])