在Python3.2和matplotlib中重缩放和归一化x轴数字

0 投票
1 回答
849 浏览
提问于 2025-04-17 22:22

我正在使用Python 3.2和matplotlib这个库。

我的图表中,x轴的数字范围在0到1000000之间。

在我的图表里,x轴的数字很长,而且互相重叠了。

我想把这些数字重新缩放到0到10之间,并且在x轴周围显示单位(比如10^6)。

请问我该怎么做呢?

任何帮助都非常感谢。

1 个回答

0

使用 set_powerlimits()

import pylab as pl
x = np.linspace(0, 1000000, 100)
y = x * 2

pl.plot(x, y)
ax = pl.gca()
xaxis = ax.xaxis
xaxis.major.formatter.set_powerlimits((0, 4))

撰写回答