# Can I adjust starting point when using ListPlot?

RandomInteger[3,3] produces a vector of length-3 randomly. But it counts index from 1. I need a vector, index of which starts from 0. Because of this, when plotting it, my x-axis starts from 1. Look at the following.

ListPlot[RandomInteger[3, 3]]


So I've searched HELP about this, and I found the option about AxesOrigin. I tried out the following.

ListPlot[RandomInteger[3, 3], AxesOrigin -> {1, 0}]


Look at the values of the axis. It's just shifting the axis without adjusting index of the vector. It is starting from 1 still.

How can I count my vectors from the index of 0?

• It is not clear what you want. If you want to have Mathematica lists accept 0 based indexing you are out of luck. If you want to have your list include 0 values that is easy just do RandomInteger[{0,3},3]. Oct 14, 2012 at 7:27

------- Edit: @@rm-rf comment -------

@@rm-rf suggested a very good idea - this is basically an option to ListPlot which I missed - DataRange. In simplest terms this works:

ListLinePlot[RandomInteger[3, 3], DataRange -> {0, 2}]


Whenever ListPlot makes graphics from a simplest list it interprets it as y-data and indexes x-data automatically starting from 1. But if you give it your own index - it will take it in account. You need to produce pairs of numbers where 1st in a pair number is your index. You can do it a number of ways, - a few equivalent examples:

data = Transpose[{Range[0, 2], RandomInteger[3, 3]}]


{{0, 3}, {1, 3}, {2, 3}}

data = Table[{k, RandomInteger[3]}, {k, 0, 2}]


{{0, 1}, {1, 1}, {2, 1}}

data = {#, RandomInteger[3]} & /@ Range[0, 2]


{{0, 3}, {1, 1}, {2, 1}}

It now will work:

ListLinePlot[data, AxesOrigin -> {0, 0},
Mesh -> All, MeshStyle -> Directive[Red, PointSize[Large]]]


• I think he simply needs DataRange...
– rm -rf
Oct 14, 2012 at 9:00
• @rm-rf excellent, slipped my mind :) If you post it as your answer I will remove my edit. Oct 14, 2012 at 9:16
• Nah, it's ok... You have a full answer with other details, so it's better in yours :)
– rm -rf
Oct 14, 2012 at 14:22

To achieve the result you want, you need to control both the PlotRange and the AxesOrigin. PlotRange controls which part of the x and y axis are display and AxesOrigin controls where the axes are placed.

ListLinePlot[RandomInteger[3, 3],
PlotRange -> {{0.9, 3.1}, {0, 3.1}},
AxesOrigin -> {1, 0},
PlotMarkers->Automatic]


One point to note is that you are not changing the indices of the random vector you have created.

Mathematica stores data in lists whose indices start at 1, what you are modifying here is the visual appearance of the plot of that data.