MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Switching x and y axes in a plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41527] RE: Switching x and y axes in a plot
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 24 May 2003 01:06:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Gregory,

First, it is convenient to define your risk function...

risk[a_, b_, c_][x_] := a x^2 - 2b x + c

The following is a regular plot with the parabola opening upward.

Plot[risk[1, 2, 3][x], {x, -3, 7},
    Frame -> True,
    FrameLabel -> {x, y},
    Axes -> False,
    PlotLabel -> "Minizing Risk",
    ImageSize -> 500];

Now, we will make the same plot using ParametricPlot. In ParametricPlot we
specifically give the x and y coordinates for the points on the curve.

ParametricPlot[{x, risk[1, 2, 3][x]}, {x, -3, 7},
    Frame -> True,
    FrameLabel -> {x, y},
    Axes -> False,
    PlotLabel -> "Minizing Risk",
    ImageSize -> 500];

That gave the same plot. Now just reverse x and y in the coordinate list,
and also in the frame labels.

ParametricPlot[{risk[1, 2, 3][x], x}, {x, -3, 7},
    Frame -> True,
    FrameLabel -> {y, x},
    Axes -> False,
    PlotLabel -> "Minizing Risk",
    ImageSize -> 500];

You might also want to adjust the AspectRatio for the new plot.

Here is some simulated data with some random noise added.

dataxy = Table[{x, risk[1, 2, 3][x] + Random[Real, {-0.4, 0.4}]}, {x, -3, 7,
        0.25}];

To make a reverse axis plot, we want to reverse {x,y} to {y,x} for each data
point. We can do that by Mapping (/@, look up Map in Help) Reverse onto the
data list.

datayx = Reverse /@ dataxy;

(You might want to look at the two data lists to see exactly what happened.)
Then plot it with...

Show[Graphics[
      {AbsolutePointSize[3],
        Point /@ datayx}],
    Frame -> True,
    FrameLabel -> {y, x},
    Axes -> False,
    PlotLabel -> "Minizing Risk",
    ImageSize -> 500];

Just as we mapped Reverse on the data list, for plotting we mapped Point
onto the data list to obtain plot Points. Another plot option that can be
used is PlotRange. If you don't specify it Mathematica shows everything that
it thinks is "interesting". That means it may exclude outliers. If you don't
like that you can specifically give the PlotRange.

Making a good plot usually involves a certain amount of trial and error and
using the various plot options. There are so many options that it takes a
little while to learn how and when to use them.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


From: Gregory Lypny [mailto:gregory.lypny at videotron.ca]
To: mathgroup at smc.vnet.net

Hello everyone,

	I'm new to Mathematica, so I hope you'll forgive my first couple of
naive questions.

	I've used Plot to graph a parabola as follows: Plot[ax^2 - 2bx + c,
{x, xMin, xMax}].  Is there any way to plot the function so that y
appears on the horizontal axis and x on the vertical?  (I realize the
parabola part is uninteresting; it's actually the solution to a
standard problem in financial economics involving the minimization of
investment portfolio risk for a given expected return.)

	Another plot-related question, if I may: do all plots require the
specification of a domain as {x, xMin, xMax}?  For example, how would I
create a scatter plot of experimental data where I have a long
two-column list or matrix consisting of x and y observations where the
data determine the domain and range?

	Sincerely,

		Gregory


	Gregory Lypny
	Associate Professor
	Concordia University
	___________________
	"Better for us if you don't understand."
		The Tragically Hip

	http://pareto.concordia.ca




  • Prev by Date: Re: Re: Tricky differential equation
  • Next by Date: RE: TraditionalForm output and subscript variable
  • Previous by thread: Re: Switching x and y axes in a plot
  • Next by thread: Re: Switching x and y axes in a plot