Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Controlling the scale of x-axis in ListPlot

1,699 views
Skip to first unread message

daniel.a...@bwinparty.com

unread,
May 31, 2011, 7:48:52 AM5/31/11
to
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

Peter Breitfeld

unread,
Jun 1, 2011, 4:30:05 AM6/1/11
to

You can change the Ticks:

yList = RandomInteger[{1, 5}, 10]
xList = RandomInteger[{1, 100}, 10] // Sort

xTicks = Table[{i, xList[[i]]}, {i, 1, Length[xList]}]
ListPlot[yList, Ticks -> {xTicks, Automatic}]


"daniel.a...@bwinparty.com" wrote:

--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

Murray Eisenberg

unread,
Jun 1, 2011, 4:31:20 AM6/1/11
to
I think what you're really asking is how to plot the vector
{y_1,...,y_n} against {1,...,n} but to label the x-coordinates with the
vector {x_1,..,x_n}. If so, here's a way, using your example for x:

x = {1, 2, 10};
y = RandomReal[{0, 1}, 3]

xTicks = Transpose[{Range[Length@x], x}]
ListPlot[y, PlotStyle -> PointSize[Large],
Ticks -> {xTicks, Automatic}]

On 5/31/2011 7:48 AM, daniel.a...@bwinparty.com wrote:
> 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
>

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Murray Eisenberg

unread,
Jun 1, 2011, 4:31:30 AM6/1/11
to
With Mathematica 8.0.1 under Windows XP:

FixedPoint[Cos, 1.0] // Timing
{0., 0.739085}

Heike Gramberg

unread,
Jun 1, 2011, 4:32:02 AM6/1/11
to
Not sure if this is what you mean, but suppose xvector={x_1,...,x_n} and yvector={y_1,...,y_n}
then you could do something like

ListPlot[yvector, Ticks -> {Transpose[{Range[Length[xvector]], xvector}], Automatic}]

Heike.

Rolf Schramek

unread,
Jun 1, 2011, 4:32:44 AM6/1/11
to
On 31 Mai, 13:48, "daniel.anders...@bwinparty.com"

Hello,

this might work:

y = {1, 3, 0, -4}
x = {1, 2, 10, 50}
ListPlot[y
, PlotStyle -> PointSize[0.03]
, Ticks -> {Transpose[{Range[Length[y]], x}], Automatic}
]

Greetings

Bob Hanlon

unread,
Jun 1, 2011, 4:33:59 AM6/1/11
to

yVal = {7, 1, 5, 4};

xVal = {1, 2, 10, 70};

ListPlot[yVal,
Ticks -> {
Thread[{Range[Length[xVal]], xVal}],
Automatic
}]


Bob Hanlon

---- "daniel.a...@bwinparty.com" <daniel.a...@bwinparty.com> wrote:

=============

daniel.a...@bwinparty.com

unread,
Jun 1, 2011, 4:30:37 AM6/1/11
to
Works like a charm! Thanks a lot!

/Daniel Andersson

Alexei Boulbitch

unread,
Jun 1, 2011, 6:54:03 AM6/1/11
to
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.b...@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
transmittal from your system. Thank you for your co-operation.


0 new messages