Reputation: 1015
I have another question about Wolfram Mathematica. Is there someone that knows how I can plot a graphic on the y axis?
I hope that the figure helps.
Upvotes: 9
Views: 13657
Reputation: 24336
You can flip the axes after plotting with Reverse
:
g = Plot[Sin[x], {x, 0, 9}];
Show[g /. x_Line :> Reverse[x, 3], PlotRange -> Automatic]
With a minor change this works for plots using Filling
as well:
g1 = Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}];
g2 = Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}, Filling -> {1 -> {2}}];
Show[# /. x_Line | x_GraphicsComplex :> x~Reverse~3,
PlotRange -> Automatic] & /@ {g1, g2}
(It may be more robust to replace the RHS of :>
with MapAt[#~Reverse~2 &, x, 1]
)
Here is the form I recommend one use. It includes flipping of the original PlotRange
rather than forcing PlotRange -> All
:
axisFlip = # /. {
x_Line | x_GraphicsComplex :>
MapAt[#~Reverse~2 &, x, 1],
x : (PlotRange -> _) :>
x~Reverse~2 } &;
To be used like: axisFlip @ g1
or axisFlip @ {g1, g2}
A different effect can be had with Rotate
:
Show[g /. x_Line :> Rotate[x, Pi/2, {0,0}], PlotRange -> Automatic]
Upvotes: 9
Reputation: 61016
Just for fun:
ContourPlot is another alternative. Using Thies function:
ContourPlot[-y*Exp[-y^2/2] - x == 0,
{x, -2, 2}, {y, 0, 4},
Axes -> True, Frame -> None]
RegionPlot is another
RegionPlot[-y*Exp[-y^2/2] > x,
{x, -2.1, 2.1}, {y, -.1, 4.1},
Axes -> True, Frame -> None, PlotStyle -> White,
PlotRange -> {{-2, 2}, {0, 4}}]
And finally, a REALLY convoluted way using ListCurvePathPlot
and Solve
:
Off[Solve::ifun, FindMaxValue::fmgz];
ListCurvePathPlot[
Join @@
Table[
{x, y} /. Solve[-y*Exp[-y^2/2] == x, y],
{x, FindMaxValue[-y*Exp[-y^2/2], y], 0, .01}],
PlotRange -> {{-2, 2}, {0, 4}}]
On[Solve::ifun, FindMaxValue::fmgz];
Off Topic
Answer to Sjoerd's None of the answers given thus far can work with Plot's Filling option
.
Reply: Not necessary
f={.5 Sin[2 y],Sin[y]};
RegionPlot[Min@f<=x<=Max@f,{x,-1,1},{y,-0.1,2.1 Pi},
Axes->True,Frame->None,
PlotRange->{{-2,2},{0,2 Pi}},
PlotPoints->500]
Upvotes: 7
Reputation: 16232
ParametricPlot[{5 Sin[y], y}, {y, -2 \[Pi], 2 \[Pi]},
Frame -> True, AxesLabel -> {"x", "y"}]
EDIT
None of the answers given thus far can work with Plot's Filling
option. Plot's output contains a GraphicsComplex
in that case (which, incidentally, breaks Mr.Wizard's replacements). To get the filling capability (it doesn't work for a standard plot without filling) you could use the following:
Plot[Sin[x], {x, 0, 2 \[Pi]}, Filling -> Axis] /. List[x_, y_] -> List[y, x]
Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}, Filling -> {1 -> {2}}]
/. List[x_, y_] -> List[y, x]
Upvotes: 9
Reputation: 2537
One possibility is to use a ParametricPlot
like this:
ParametricPlot[
{-y*Exp[-y^2], y}, {y, -0.3, 4},
PlotRange -> {{-2, 2}, All},
AxesLabel -> {"x", "y"},
AspectRatio -> 1/4
]
Upvotes: 8
Reputation: 4420
Depending on how you wanted the axis labels to show, you could just wrap the code for the original Plot in the Rotate function.
Upvotes: 5