Re: Controlling the scale of x-axis in ListPlot

• To: mathgroup at smc.vnet.net
• Subject: [mg119388] Re: Controlling the scale of x-axis in ListPlot
• From: Alexei Boulbitch <alexei.boulbitch at iee.lu>
• Date: Wed, 1 Jun 2011 06:54:06 -0400 (EDT)

```Hi, Daniel,

Denote the vectors you want to plot: xVect and yVect. For example:

xVect = {1, 2, 10, 20};
yVect = Table[RandomInteger[{1, 5}], {Length[xVect]}]

{5, 1, 1, 2}

You did not write it explicitly, but I guess, that in your case xVect goes in the increasing order, e.g.
you cannot have something like {1,20,10,2}, can you? I assume, you cannot. Let us first
form a list (entitled lst) with points that are equidistant along Ox:

lst = Transpose[{Range[Length[yVect]], yVect}]

{{1, 5}, {2, 1}, {3, 1}, {4, 2}}

If you plot it, you will have the points with the abscisses 1,2,3 and 4.
Now it is only necessary to rename them. This may be done with the option Ticks
of the command ListPlot. Let us construct this option defining the x-projection:

xTicks = Table[{i, xVect[[i]]}, {i, 1, Length[xVect]}]

{{1, 1}, {2, 2}, {3, 10}, {4, 20}}

Now the final command takes the form:

ListPlot[lst, Ticks ->  {xTicks, Automatic}, AxesOrigin ->  {0, 0}]

Try it.

Have fun, Alexei

Hi,

I need to plot two a vector {y_1,...,y_n} against a vector {x_1,...,x_n}
and I want to the latter to be distributed with equal distances between
the elements. Mathematica automatically scales the x-axis so that it is
linear with respect to the x-values, i.e. if x={1,2,10}, then the distance
between the second and third element will be eight times longer than the
distance between the second and first element. I would like the distances
to be of equal length.

Any ideas?

Cheers,
Daniel

--
Alexei Boulbitch, Dr. habil.
Senior Scientist
Material Development

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 CONTERN
Luxembourg

Tel: +352 2454 2566
Fax: +352 2454 3566
Mobile: +49 (0) 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu

www.iee.lu

--

This e-mail may contain trade secrets or privileged, undisclosed or
otherwise confidential information. If you are not the intended
recipient and have received this e-mail in error, you are hereby
notified that any review, copying or distribution of it is strictly
prohibited. Please inform us immediately and destroy the original