简体   繁体   English

Matplotlib:绘制对数时的非对数标签

[英]Matplotlib:non logarithmic labels when plotting logarithm

I am plotting a histogram, taking the logarithm of the quantity before plotting, (instead of choosing a logarithmic scale for my plot) and in the tick labels on the x axis I obviously get the logarithm. 我正在绘制一个直方图,在绘制之前取数量的对数(而不是为我的图选择对数比例),并且在x轴的刻度标签中,我显然得到了对数。 I would like labels to show the scientific notation instead: in other words I would like 10^3 instead of 3, for example. 我希望标签显示科学符号:换句话说,例如,我希望10 ^ 3而不是3。

Is there any way to do that? 有什么办法吗? I saw other questions, like Matplotlib - logarithmic scale, but require non-logarithmic labels , but this is not the same thing, I didn' use ax.set_xscale('log') . 我看到了其他问题,例如Matplotlib-对数刻度,但是需要非对数标签 ,但这不是同一回事,我没有使用ax.set_xscale('log') Here is a line of my code: 这是我的代码行:

ax[0, 0].hist(np.log10(bh_100[:, 0]),bins=15, ls='dashed', color= 'b',   log=True, label = 'Bh-bh')

You can always use set_xticklabels to set the labels as you require them 您随时可以根据需要使用set_xticklabels设置标签

For example, you can do: 例如,您可以执行以下操作:

ax.set_xticklabels(['10^{%d}'%i for i in range(5)])

or LaTeX-style: 或LaTeX样式:

ax.set_xticklabels(['$10^{%d}$'%i for i in range(5)])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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