问题描述
我有一个matplotlib图,该图正在绘制始终被称为纳秒(1e-9)的数据.在y轴上,如果我有数十纳秒的数据,即在图44e-9中,轴上的值显示为4.4,其中+ 1e-8为偏移量.反正有强制轴以+ 1e-9偏移显示44吗?
I have a matplotlib figure which I am plotting data that is always referred to as nanoseconds (1e-9). On the y-axis, if I have data that is tens of nanoseconds, ie. 44e-9, the value on the axis shows as 4.4 with a +1e-8 as an offset. Is there anyway to force the axis to show 44 with a +1e-9 offset?
我的x轴也是如此,该轴显示+ 5.54478e4,我希望它显示+55447的偏移量(整数,无小数-该值以天为单位).
The same goes for my x-axis where the axis is showing +5.54478e4, where I would rather it show an offset of +55447 (whole number, no decimal - the value here is in days).
我已经尝试了一些类似的事情:
I've tried a couple things like this:
p = axes.plot(x,y)
p.ticklabel_format(style='plain')
对于x轴,但这不起作用,尽管我可能使用不正确或对文档中的内容有误解,有人可以指出我正确的方向吗?
for the x-axis, but this doesn't work, though I'm probably using it incorrectly or misinterpreting something from the docs, can someone point me in the correct direction?
谢谢,乔纳森
我尝试使用格式化程序进行操作,但尚未找到任何解决方案...:
I tried doing something with formatters but haven't found any solution yet...:
myyfmt = ScalarFormatter(useOffset=True)
myyfmt._set_offset(1e9)
axes.get_yaxis().set_major_formatter(myyfmt)
和
myxfmt = ScalarFormatter(useOffset=True)
myxfmt.set_portlimits((-9,5))
axes.get_xaxis().set_major_formatter(myxfmt)
顺便提一句,我实际上对偏移号"对象实际所在的位置感到困惑……它是主要/次要刻度线的一部分吗?
On a side note, I'm actually confused as to where the 'offset number' object actually resides...is it part of the major/minor ticks?
推荐答案
我遇到了完全相同的问题,这两行代码解决了该问题:
I had exactly the same problem, and these two lines fixed the problem:
y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
ax.yaxis.set_major_formatter(y_formatter)
这篇关于matplotlib:将轴偏移值格式化为整数或特定数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!