matplotlib对数轴:仅显示10的幂 [英] matplotlib log axis: display powers of 10 only
本文介绍了matplotlib对数轴:仅显示10的幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对数图,x 轴的范围从 10^9 到 10^12.(这是我第一次发布,因此我无法发布自己的地块图像)
I have a log-log plot with range of x-axis from 10^9 to 10^12. (This is my first time posting so I am unable to post an image of my plot)
我想更改x和y轴,以便仅显示10的幂.x轴上的9、10、11、12之类的东西.
I would like to change the x and y axes so that only the powers of 10 are displayed. Something like 9, 10, 11, 12 on the x-axis.
我使用了 matplotlib.ticker.LogFormatterExponent(base = 10.0,labelOnlyBase = True)
,但它不能完全完成这项工作.有什么建议吗?
I used matplotlib.ticker.LogFormatterExponent(base=10.0, labelOnlyBase=True)
but it does not quite do the job. Any suggestions?
推荐答案
LogFormatterExponent(base=10.0, labelOnlyBase=True)
正常工作.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker
x = 10**np.linspace(8.5,12.6)
y = np.sin(x)
fig,ax = plt.subplots()
ax.scatter(x,y)
ax.set_xscale('log')
ax.set_xlabel("Quantity [$10^{x}]$")
logfmt = matplotlib.ticker.LogFormatterExponent(base=10.0, labelOnlyBase=True)
ax.xaxis.set_major_formatter(logfmt)
plt.show()
这篇关于matplotlib对数轴:仅显示10的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文