switching axes in Plot?

  • Follow


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


0
Reply John.Finnigan (1) 2/11/2009 10:20:58 AM


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





John.Finnigan@csiro.au 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 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

> 

> 



0
Reply dh1 (452) 2/12/2009 11:33:18 AM


Hi,

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

Regards
   Jens

John.Finnigan@csiro.au 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 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
> 
> 

0
Reply kuska (2791) 2/12/2009 11:36:09 AM

In article <gmu8qa$glt$1@smc.vnet.net>, <John.Finnigan@csiro.au> 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 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?

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

0
Reply jeanmarc.gulliet (2157) 2/12/2009 11:36:52 AM

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.



0
Reply Alexei.Boulbitch (378) 2/12/2009 11:42:36 AM

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.Finnigan@csiro.au 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 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



0
Reply hanlonr (2281) 2/13/2009 8:38:59 AM

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

0
Reply windlessaegis (1) 7/19/2012 7:52:07 AM

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,  <windlessaegis@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?
>> 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}]
>

0
Reply hanlonr357 (740) 7/20/2012 7:58:44 AM

7 Replies
39 Views

(page loaded in 0.343 seconds)

Similiar Articles:













7/21/2012 6:33:15 PM


Reply: