Home > plotting > Can I adjust starting point when using ListPlot?

# Can I adjust starting point when using ListPlot?

October 14Hits:2

`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?

------- 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]]]
```
```

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.

Tags:plotting

## Related Articles

• ### Can I adjust starting point when using ListPlot?October 14

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

• ### Adjust the opacity of the lines in a ListPlotApril 30

Here is what I am trying to plot: randomWalk := NestList[# + RandomReal[{-1, 1}] &, 0, 1000]; Show[Table[ListPlot[randomWalk, Joined -> True], {100}], PlotRange -> Automatic] Which gives: What I'd like to do is give the lines a bit of transparen

• ### ListPlot: Adding Line with Epilog to automatic GridLines - adjusting StyleDecember 22

I want to draw ListPlots with automatic GridLines and add a custom line. My solution is to use the Epilog option. To make sure that the automatic GridLines and my custom line have the same style, I create a style Directive and use the GridLinesStyle

• ### Change the order of magnitude on the y axis Ticks with ListPlot June 17

This question already has an answer here: About number truncation of ticks display in ListPlot 2 answers When I make a plot like Plot[Exp[x], {x, 1 - 10^-9, 1}] The resulting plot looks like . Notice all the ticks on the x-axis are all labeled 1. Is

• ### How can I set different opacity values for the background of a ListPlotDecember 11

In the following example: ListPlot[{1, 2, 3}, Background -> Green] how can I set the Opacity[] for the background such that the opacity increases from top to bottom? --------------Solutions------------- Background takes only simple parameters. You co

• ### How to adjust parameters to experimental data on a NDSolve problemMay 11

I have 2 differential equations with 2 variables, x and y,which are a function of t and I have the parameters k1, k2 y k3. dx/dt=-k1 x2+ k2 x y dy/dt=k1 x2-k2 x y- k3 y I have to adjust the equations to the following experimental data xo=70.26, x(t=7

• ### ListPlot under conditionsJuly 29

I have a data file containing several columns and thousands lines of data. Below I present a small portion of it, in order to express my issue: -0.54 0.09 -.3983969954588588E-02 0.2776322403476376E+00 0.5000000000000000E+05 0.1217096235496098E-13 0 -

• ### In a ListPlot of LinearModelFit, plot error bandJune 13

This is similar to this question. The fitted line can be plotted alongside with the data with this code: Show[ListPlot[data], Plot[lm[x], {x, 0, 5}]] I would like to include a band around this line indicating the average error. How can I do this? Exa

• ### How can I adjust ContourPlot in Mathematica?November 12

I have problem because of the max point and min point, when I have too high or low data point, it just make it white. Here is example of data Data = Table[ 1/Sqrt[x^2 + y^2] + Cos[x*y] - 1/Sqrt[(x - 0.5)^2 + (y - 0.5)^2], {x, -3.01, 3, 0.1}, {y, -3.0

• ### Incorrect Output of ListPlot using PlotMarkers with textNovember 6

I am not sure what I am doing wrong in my code. I just want illustrate four columns consisted of different numbers as plot markers. ListPlot[{{1, 2, 3, 4}, {2, 1}, {2, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 2}}, PlotMarkers -> {"\[Pi]", "8"

• ### Font Adjuster Panel for Flash MX 2004August 4

Well, this is one that I use in Fireworks all the time, and thought I'd port it over to Flash just due to the sheer time-saving nature of the panel. Altering the text size of single or multiple selected text areas can be a royal pain either having to

• ### How do I adjust mouse sensitivity on Dell Mini9 running Ubuntu?May 21

I recently picked up a Dell Mini9 netbook running Ubuntu 8.04. It runs great and I love it, but there's one glaring issue out of the box. The trackpad mouse and mousewheel are way too sensitive. I'm able to adjust mouse acceleration and sensitivity i

• ### When can I adjust partition sized in Leopard?June 19

The version of Disk Utility that comes with Mac OS X 10.5 will let you resize existing partitions on a partitioned drive -- some of the time. What determines if it will let you adjust partition sizes or not? --------------Solutions------------- Fragm

• ### Why do I need to auto-adjust my LCD monitor when switching between Windows and Linux with a KVM?July 13

I routinely work in Windows, Linux, and Mac, so I obtained this KVM switch: http://catalog.belkin.com/IWCatProductPage.process?Product_Id=404586 Now, whenever I switch between Linux (Ubuntu 9.04) and Windows (XP SP3), I have to auto adjust my monitor

• ### How to adjust Aspect Ratio in Windows Media CenterAugust 21

Is there any way of adjusting the aspect ratio of movies I view in Windows Media Center on Windows 7 RTM x64? Any hidden features? Any brilliant light weight plugins? Using Shark007 Codecs, and otherwise just default Media Center and Media Player. I

• ### How can I get a cell in Excel to automatically adjust its height to fit the wrapped text contents?August 25

I have a cell with wrapped text content in Excel and I want to format the cell so that its height will adjust to fit the content which can span over several lines. How can I achieve this behavior? --------------Solutions------------- From http://supp

• ### How do I make my "Fn + Volume Up/Down" keys adjust my headphone channel in Ubuntu Jaunty?August 26

I always have my master channel muted, and I switched the volume applet to adjust the headphone channel. This way, sound never comes out of my speakers, but it's always on when I plug headphones in. However, when I use my Fn keys to adjust volume, th

• ### Litestep disables volume adjustment buttonSeptember 9

I've been using a Logitech Clearchat Comfort headset for a couple months now, and never had any issues with it until the volume adjustment buttons, that's the thing in the middle of the cord in the stock picture above, decided to quit on me. Sound an

• ### Adjusting the refresh rate of Firefox Live Bookmarks?September 18

Does anyone know how to adjust how often Firefox Live Bookmarks (a.k.a. Live Titles) refresh in the toolbar? --------------Solutions------------- Change The Default Reloading Time of Firefox 3 Live Bookmarks Feature. According to that article you wil