x-axis display

Hello,

I’m plotting some experimental data and found my x axis variable are displayed like 1, 2, 3, +1000. It seems depend on how you set a stopper or something.
I’m wondering how to make it display just 1001, 1002, 1003?

thanks!

Hello,

I’m plotting some experimental data and found my x axis variable are displayed like 1, 2, 3, +1000. It seems depend on how you set a stopper or something.
I’m wondering how to make it display just 1001, 1002, 1003?

thanks!

The behavior you are seeing is called “tick offset” and is controlled by the axis tick formatter. This can be controlled in different ways, but here is one approach:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(1000, 1010)
y = np.random.random((10,))

fig = plt.figure()
ax = fig.gca()

ax.plot(x, y)

Get the formatter for the major ticks of the x-axis

and set the ‘useOffset’ attribute to False.

ax.get_xaxis().get_major_formatter().set_useOffset(False)

plt.show()

I hope that helps!
Ben Root

···

On Mon, Dec 13, 2010 at 9:10 PM, Xunchen Liu <xunchen.liu@…287…> wrote:

Hello,

I’m plotting some experimental data and found my x axis variable are displayed like 1, 2, 3, +1000. It seems depend on how you set a stopper or something.
I’m wondering how to make it display just 1001, 1002, 1003?

thanks!