python - matplotlib:将轴偏移值格式化为整数或特定数字

标签 python matplotlib

我有一个 matplotlib 图形,我正在绘制始终称为纳秒 (1e-9) 的数据。在 y 轴上,如果我有数十纳秒的数据,即。在图 44e-9 中,轴上的值显示为 4.4,偏移量为 +1e-8。无论如何强制轴显示 44 偏移 +1e-9?

我的 x 轴也是如此,其中轴显示 +5.54478e4,我希望它显示 +55447 的偏移量(整数,没有小数 - 这里的值以天为单位)。

我已经尝试了一些这样的事情:

p = axes.plot(x,y)
p.ticklabel_format(style='plain')

对于 x 轴,但这不起作用,尽管我可能使用不正确或误解了文档中的某些内容,有人能指出我正确的方向吗?

谢谢, 乔纳森

Problem illustration


我尝试使用格式化程序做一些事情,但还没有找到任何解决方案...:

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)

在旁注中,我实际上对“偏移量”对象实际驻留的位置感到困惑......它是主要/次要刻度的一部分吗?

最佳答案

我遇到了完全相同的问题,这些行解决了问题:

from matplotlib.ticker import ScalarFormatter

y_formatter = ScalarFormatter(useOffset=False)
ax.yaxis.set_major_formatter(y_formatter)

关于python - matplotlib:将轴偏移值格式化为整数或特定数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3677368/

相关文章:

python - 在python中读取文件

python - 如何在 Python 的 curses 中获得更多颜色?

python - Matplotlib 中的 Tukey Boxplots - 代码中的异常值逻辑?

python - 创建描述一个月内事件发生次数的时间序列堆积条形图的问题

python - matplotlib 中的自定义标记

python - 是否可以有多个字幕?

python - scipy curve_fit 在拟合傅里叶函数时不产生平滑的图形

python - 安装 Python 包 : setup. py install - 错误:未提供命令

python - 在 django-taggit 中,如何获取与特定用户关联的对象的标签?

python - 在 Python 中通过套接字发送的字符串一旦 .recv'd 后将不会与等效字符串进行比较