Let's say, I have a function $y = f(x)$ which I want to plot on Mathematica in such a way that the traditional X-Axis is the Y-Axis and vice-versa.

I know that I can plot the function,

Plot[f(x), {x, x_min, x_max}, PlotRange[y_min, y_max]]

But is there is any way to plot the function in a way that after plotting the function the axes are switched?

I want to avoid the inverse functions since there would be some singularities that might pop out by doing that and I want to avoid that.

For example, $y = x^2$ would give me a parabola with directrix on X-Axis and focus on Y-Axis. I want to plot the same equation in such a way that the parabola opens towards the "right" instead of "up" in the traditional sense of the cartesian plane.

I hope I am clear. Thanks.

  • 2
    $\begingroup$ You could use ParametricPlot. Try ParametricPlot[{x^2, x}, {x, 0, 5}]. $\endgroup$
    – MarcoB
    Mar 16, 2022 at 20:03

2 Answers 2


"13.0.0 for Mac OS X ARM (64-bit) (December 3, 2021)"

f[x_] := x^3;
parplot1 = 
  ParametricPlot[{x, f[x]}, {x, 0, 10}, 
   PlotRange -> {{0, 10}, {0, 50}}, ImageSize -> 200, 
   AspectRatio -> 1];
parplot2 = 
  ParametricPlot[{f[x], x}, {x, 0, 10}, 
   PlotRange -> Reverse[PlotRange[parplot2]], ImageSize -> 200, 
   AspectRatio -> 1];
Row[{parplot1, parplot2}, Spacer[100]]



@bmf gives a very practical solution. Here is a more tricky way...

Given a plot whose axes you wish to interchange

g = Plot[Sin[π x], {x, 1, 3}]

enter image description here

do some internal fiddling

g /. {u_Line :> Map[Reverse, u, {2}],
     (v : (AxesOrigin | PlotRange) -> u_List) :> (v ->  Reverse[u])}

I did this by looking at the internal structure of g and working out where I needed to interchange x and y.

enter image description here

  • $\begingroup$ Very nice alternative approach (it was a (+1) since I saw it, but only now I got able to leave a comment :-) ). $\endgroup$
    – bmf
    Mar 17, 2022 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.