COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### switching axes in Plot?

• Email
• 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

See related articles to this posting

```
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 (415) 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

```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 (841) 7/20/2012 7:58:44 AM

7 Replies
59 Views

Similar Articles

12/11/2013 10:12:59 PM
[PageSpeed]

Similar Artilces:

Plotting Graphs on Same Plot With Axes Rescaled To Include Largest Range
Is it possible to plot a set of 2D graphs on the same graph, with the x,y-axes being rescaled to include the entire graph for each overplot? The problem I am having is if I have two graphs, and the second graph has a larger range than the first graph, both graphs will be on the axes of the first graph instead of the second graph. This clips the first graph which I do not want. Using the /NOERASE keyword keeps ALL of the axes on a set of plot, instead of the one with the largest range of values. Ideally, I am looking for a keyword to automatically set the graph axes to the data set with the ...

Coordinate axes inside plot?
Hi all Does anybody know how to make coordinate axes appear inside a plot? For example: x = -20:0.1:20; y = x.^3; plot(x,y) I want axes at x=0 and y=0, not at x=-20 and y=-8000 as is the case here. Is that possible? /Fred Search help axis "Fred" <f97frer@hotmail.com> wrote in message news:ef42d5b.-1@webcrossing.raydaftYaTP... > Hi all > > Does anybody know how to make coordinate axes appear > inside a plot? > > For example: > > x = -20:0.1:20; > y = x.^3; > plot(x,y) > > I want axes at x=0 and y=0, not at x=-20 and y=-8000 as is > ...

Axes in Fast-3D plot with 49G+
Hi, How can I include axes in Fast-3D plot? For example, lets say I want to plot x+y+z=2 surface using Fast-3D, how can I create a plot with the X-axis, Y-axis, and Z-axis shown (with the intersection to the axes)? f4ding > How can I include axes in Fast-3D plot? Write a new one. . . =) That axis are already there. They aren't huge ones that cover the screen though. They are small tiny things down above the TRACE button. They are even labeled for you nicely. . . ;-) TW Haaaa, the obvious answer. LOL. So you are saying there isn't a way to do this (besides the obvious)...

Setting axes in "plot"
Hi, It seems that the default axes in function "plot" are the frame box. How can I convert them to the traditional Cartesian axes at origin? Thanks, Gang Gang Chen wrote: > > > Hi, > > It seems that the default axes in function "plot" are the frame > box. How can > I convert them to the traditional Cartesian axes at origin? > > Thanks, > Gang > > > you can define your axes in matlab, using axes does this help ? ...

Plot section of data on existing axes
Hello all, I have a number of signals I want to plot together on a graph. For one or more of those signals, I only want to plot a smaller section in the middle of the data range of the other signals. Let's say one signal is indexed from 1 to 500. I want to plot a second signal from 100 to 200 only. Currently, the only way I know to do this it to pad the second signal with 99 zeros then plot it. How can I make a "floating" set of data in a graph? Thank you! "John " <John@Twisthink.com> wrote in message news:hm3cj6\$jgl\$1@fred.mathworks.com... > Hello al...

Different axes in a single plot in guide
Hi. I am trying draw two different plots with different y-axes into a single panel on my GUI form (using guide for GUI creation). For normal plotting into a figure window this appears to be easy (documentation: "Using Multiple X- and Y-Axes"). But how can I do this in such a GUI form? The "Axes" control is an axes object itself and thus cannot contain different types of axes. Any ideas? Regards, Jan Jan, To my knowledge, no axes object ever contains another axes object. The second one is just created on top. I can't try it on my comp. at the moment, but am w...

display plot in axes from a seperate m file?
currently, i have a pseudo.m file that generates a figure that has a few points plotted. right now, I want to make a gui that can take the figure pseudo.m generates and put it in the axes that is part of my gui. how do i do this? keep in mind my matlab skills arent all that great. ...

Problem with Multiple Axes (Plots) on one Figure
Hi, I am trying to put 8 seperate plots (abxes) on one figure. I am currently just using the function subplot(2, 4, 8) to display the 8 plots evenly spaced out on two rows , but the plots are too spaced out and I wanted to be able to push them closer together. Is there any way to do this? Btw, I've looked over the axes function and I couldn't get it to accomplish the task. Any help would be greatly appreciated. Does anybody know how? "Ahmad Siddiqi" <clickster100@yahoo.com> wrote in message <hsunkk\$78n\$1@fred.mathworks.com>... > Hi, > > I...

Plot pkg
Hello, You can make Multiple Y Axes plots in Excel using Multy_Y or EZplot. There is a demo version at www.OfficeExpander.com Cheers! ______________________________________ Hello, I'm searching for a plotting package that will allow multiple y axes of different scales. For example I'd like to overlay 4 or 5 time series with each series having a separate axis. Does anyone know of such a package? Thank you, Frank ...

[newbie] Plotting 3D axes and choosing direction by mouse
Hi, I'm an OpenGL newbie (I only know the "basics" of this clean and cool API!) I have two questions, related each other. 1. I'd like to plot the three X, Y, Z axes of a Cartesian coordinate system in space. I'd like to use arrows to draw each axis, but I don't know how to draw an arrow...? Is there any function in GLU? (it seems not to me :( 2. In this 3D space, the user moving the mouse has to be able to specify a unit-vector in the 3D space...but I don't know how can I make the user choose a unit-vector (i.e.: a *direction*) in 3D space by mouse... ...

How to edit a plot axes using MATLAB5.3 on window XP
I need help with the following problem: I am using a MATLAB 5.3 (release 11) on window XP, when I try to edit the axes properties of a plot by double clicking the specific plot, a new dialogbox pops-up. However only part of this dialogbox appears in the left upper corner of my screen. Moreover, the dialog box can neither be resized nor moved. ...

plotting a 3-d sine wave varying with time x,y,z axes.
Is it possible to plot a 3 dimensional surface sine wave which varies with time ...such as when a stone is dropped on the surface of water and the waves are viewed from above the surface ...a single 2-D sine wave with x,y & time variation can be converted into a surface with the same pattern of variation, right.Any ideas? Here is the code: x=-15:0.5:15; y=-15:0.5:15; [X,Y] = meshgrid(x,y); % greate rectangullar mesh R=sqrt(X.^2+Y.^2); %rasius k=1; % wave vector phi=0; % phase Z=sin(k*R+phi); surf(X,Y,Z); axis equal; ----------------------------------------- Maxim Vedenev...

My switch is not switching
Hi, To handle a custom protocol over a serial line I am trying to implement a very small and simple state machine. The states are declared as enum: enum CommState { CS_WAIT_FOR_STX, CS_WAIT_FOR_T, CS_WAIT_FOR_0, CS_WAIT_FOR_Key, CS_WAIT_FOR_ETX }; I wanted to switch on the current state and handle whatever needs to be done in that state plus the transition to the next one. However, my switch() is always falling through to the default case. I have cut down my code to this nonsensical example: CommState commState=3DCS_WAIT_FOR_STX; if (commState=3D=3DCS_WAIT_FOR_STX) { s...

How do you plot multiple plots in an array with no space between plots?
I have some data that I'd like to plot in 12 small square plots, and then arrange those 12 plots into a 4x3 rectangular array. The thing I'd like to do that I don't know how to do is simplify the 4x3 rectangular array by squeezing the plots together, such that there is no space between the plots: the right-hand border of a plot should be coincident with the left-hand border of the plot to its right, and its lower border should be coincident with the upper border of the plot right below it. Imagine 12 squares on a checkerboard; that's what I'm aiming for. As far as I ca...

PLOTS and the new PLOT
Hi all, Can anyone tell me how the new PLOT() handles scalars/1-element arrays for X and Y? Or do you still have to use PLOTS? If you have a graphic created with PLOT(/buffer), will a subsequent call to PLOTS go on the right plot? Or will it try to go in a window? Thanks! --Gray On Aug 21, 9:13=A0am, Gray <grayliketheco...@gmail.com> wrote: > Can anyone tell me how the new PLOT() handles scalars/1-element arrays > for X and Y? =A0Or do you still have to use PLOTS? > > If you have a graphic created with PLOT(/buffer), will a subsequent > call to PLOTS...

Switch Within A Switch
Hello, I am working on an Adobe Acrobat file that uses javascript for calculations. I am trying to create a field that uses two other fields to determine a number value. I think this requires a switch within a switch, but I am not sure how to do this, as I am a beginner when it comes to javascript. In esscense, I want to set up a code so that each case of value A is calculated at each case of value B. Example: There are 9 cases for value A. There are 30 cases for value B. I want to produce a number at each value B for each case in value A. I hope I have explained what I want to do well e...

How to plot this? special kind of plot...
Hi all, I am having problems trying to find out how to plot this data: I have polar coordinates and for each pair (theta, radius) i have a value which I want to plot as an intensity level. Any ideas how to do this? thanks a lot. Edgar Hi Edgar, try this: % your data theta = linspace(0,pi,100); radius = ones(1,100); value = 100*rand(1,100); % convert polar to cartesian [x,y] = pol2cart(theta,radius); % scatter plot: bubble size indicates value on a 2D plane scatter(x,y,value) % stem3 plot: line length in 3D space indicates value figure stem3(x,y,value) Regards, Heinrich Sounds like...

Re: Contour Plot + Points Plot
Hi, I think it can be done by Annotate, something like: data anno; set a; retain xsys '2' ysys '2' when 'a' function 'symbol' text 'circle'; run; proc gcontour data=a annotate=anno; plot y*x=z; run; ...

[plot] Updating matrix data in plot
Hello everyone! I have a little problem. I plot a matrix data and then I want to update 'xdata' and 'ydata' by using 'set'. This code explains my problem: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x = [1 1 2 2 1; 5 5 6 6 5]; y = [1 2 2 1 1; 5 6 6 5 5]; h = plot(x',y'); %I plot some (i this example two) rectangles. axis([0 7 0 7]); x = x+1; %I add a constant to make an illusion of movement. y = y+1; %As above. set(h,'xdata',x','ydata',y') % <- error %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% When I use 'set'...

Adding a scatter plot to a contour plot
I have a contour plot of X, Y, Z where X and Y are 5 x 1 matrices. I would like to add a scatter plot of X and Y to the contour plot. Can someone please tell me how to add a scatter plot to the existing contour plot? Thank you. RRS wrote: > > > I have a contour plot of X, Y, Z where X and Y are 5 x 1 matrices. > I > would like to add a scatter plot of X and Y to the contour plot. > Can > someone please tell me how to add a scatter plot to the existing > contour plot? Thank you. try: contour(x,y,z); hold on scatter(x,y); hold off ...