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

switching axes in Plot?

7,102 views
Skip to first unread message

John.F...@csiro.au

unread,
Feb 11, 2009, 5:20:58 AM2/11/09
to
When using Plot to plot F[x] as a function of x, Mathematica automatically =
assigns the independent variable x to the horizontal axis and the dependent=
variable F[x] to the horizontal. I often want to switch this around so th=
at the independent variable runs on the vertical axis and the dependent on =
the horizontal. I feel sure there ought to be a simple way to tell Plot to=
make this change but I have never found it and instead have resorted to co=
nvoluted approaches. Can anyone tell me what the simple trick is, if it ex=
ists?
Thanks
John Finnigan


dh

unread,
Feb 12, 2009, 6:33:18 AM2/12/09
to

Hi John,

the cheapest solution is simply to rotate the picture:

Rotate[Plot[Sin[x], {x, 0, 10}], Pi/2]

However, that is probably not good enough as the labels face the wrong

way. A better way is to use ParametricPlot:

ParametricPlot[{Sin[x], x}, {x, 0, 10}]

hope this helps, Daniel

Jean-Marc Gulliet

unread,
Feb 12, 2009, 6:36:52 AM2/12/09
to

One of the most straightforward and less error prone way of switching
the x- and y-axis must be by using ParametricPlot as illustrated below.

f[x_] = x^2 Sin[x];
Plot[f[x], {x, -Pi, 2 Pi}]
ParametricPlot[{f[x], x}, {x, -Pi, 2 Pi}]

Regards,
--Jean-Marc

David Park

unread,
Feb 12, 2009, 6:37:03 AM2/12/09
to
John,

Use ParametricPlot instead of Plot. Like this:

ParametricPlot[{Sin[x], x}, {x, 0, 2 \[Pi]}]


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


From: John.F...@csiro.au [mailto:John.F...@csiro.au]


When using Plot to plot F[x] as a function of x, Mathematica automatically =
assigns the independent variable x to the horizontal axis and the dependent=
variable F[x] to the horizontal. I often want to switch this around so th=
at the independent variable runs on the vertical axis and the dependent on =
the horizontal. I feel sure there ought to be a simple way to tell Plot to=
make this change but I have never found it and instead have resorted to co=
nvoluted approaches. Can anyone tell me what the simple trick is, if it ex=
ists?

Thanks
John Finnigan


Jens-Peer Kuska

unread,
Feb 12, 2009, 6:36:09 AM2/12/09
to
Hi,

Show[Plot[{Cos[x], Sin[x], Sin[x]/x}, {x, 0, 8 Pi}] /.
Line[pnts_] :> Line[Reverse /@ pnts], PlotRange -> All]

Regards
Jens

Alexei Boulbitch

unread,
Feb 12, 2009, 6:42:36 AM2/12/09
to
John, try this simple way:

f[x_] := Sin[2 x];
ParametricPlot[{f[x], x}, {x, 0, 2}]

try also this one:

ListLinePlot[Table[{Sin[2 x], x}, {x, 0, 2, 0.01}]]

Have success, Alexei

When using Plot to plot F[x] as a function of x, Mathematica automatically =
assigns the independent variable x to the horizontal axis and the dependent=
variable F[x] to the horizontal. I often want to switch this around so th=
at the independent variable runs on the vertical axis and the dependent on =
the horizontal. I feel sure there ought to be a simple way to tell Plot to=
make this change but I have never found it and instead have resorted to co=
nvoluted approaches. Can anyone tell me what the simple trick is, if it ex=
ists?
Thanks
John Finnigan


--
Alexei Boulbitch, Dr., Habil.
Senior Scientist

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

Phone: +352 2454 2566
Fax: +352 2454 3566

Website: 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.

Bob Hanlon

unread,
Feb 13, 2009, 3:38:59 AM2/13/09
to
ParametricPlot[{Sin[x], x}, {x, 0, 4 Pi},
AspectRatio -> 1/GoldenRatio]

ParametricPlot[{Tan[x], x}, {x, 0, 2 Pi},
AspectRatio -> 1/GoldenRatio,
Exclusions -> {Pi/2, 3 Pi/2}]


Bob Hanlon

---- John.F...@csiro.au wrote:

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

windle...@gmail.com

unread,
Jul 19, 2012, 3:52:07 AM7/19/12
to
On Wednesday, February 11, 2009 5:20:58 AM UTC-5, (unknown) wrote:
> When using Plot to plot F[x] as a function of x, Mathematica automatically
> assigns the independent variable x to the horizontal axis and the dependent variable F[x] to the horizontal. I often want to switch this around so that the independent variable runs on the vertical axis and the dependent on the horizontal. I feel sure there ought to be a simple way to tell Plot to make this change but I have never found it and instead have resorted to convoluted approaches. Can anyone tell me what the simple trick is, if it exists?
> Thanks
> John Finnigan

Hi,

I just found this looking for the answer myself. Then it hit me: try changing the order that you define the variables within the plot operation.

So as an example, given:

ContourPlot[
Evaluate[Re[
Product[x + I y - (a + I b), {a, -2, 2}, {b, -2, 2}]]], {x, -3,
3}, {y, -3, 3}]

To swap axes, just define y and then x -- like this:

ContourPlot[
Evaluate[Re[
Product[x + I y - (a + I b), {a, -2, 2}, {b, -2, 2}]]], {y, -3,
3}, {x, -3, 3}]

Bob Hanlon

unread,
Jul 20, 2012, 3:58:44 AM7/20/12
to
ParametricPlot is also useful

f[x_] = x^2 - 5 x + 6;

Plot[f[x], {x, 1, 4}]

ParametricPlot[{f[x], x}, {x, 1, 4}]


Bob Hanlon


On Thu, Jul 19, 2012 at 3:51 AM, <windle...@gmail.com> wrote:
> On Wednesday, February 11, 2009 5:20:58 AM UTC-5, (unknown) wrote:
>> When using Plot to plot F[x] as a function of x, Mathematica automatically
>> assigns the independent variable x to the horizontal axis and the dependent variable F[x] to the horizontal. I often want to switch this around so that the independent variable runs on the vertical axis and the dependenton the horizontal. I feel sure there ought to be a simple way to tell Plot to make this change but I have never found it and instead have resorted to convoluted approaches. Can anyone tell me what the simple trick is, if it exists?

danil...@gmail.com

unread,
Jan 28, 2014, 6:02:36 AM1/28/14
to
Thank you

0 new messages