3
$\begingroup$

I have a list of data. I ploted with ListPlot but I to want flip the axes with a easy way. Instead to Plot (y,U) I want to plot (U,y). There is some option in ListPlot?

Thanks.

enter image description here

$\endgroup$
2
  • 8
    $\begingroup$ ListPlot[Reverse[points, 2]] or something like it should be useful. $\endgroup$ Commented Aug 30, 2017 at 17:10
  • $\begingroup$ Thanks! Solved. $\endgroup$
    – Mateus
    Commented Aug 30, 2017 at 17:13

1 Answer 1

3
$\begingroup$

From the comments, an easy and efficient way to flip the axes in ListPlot, ListLinePlot and other 2D list plotting functions is to exchange the positions of the abscissa and the ordinate in the list of points:

points = Table[{n, n^Sin[n]}, {n, 1, 10, 0.25}];

{ListPlot[points, ImageSize -> Medium], ListPlot[Reverse[points, 2], ImageSize -> Medium]}

plots

what is equivalent to

ListPlot[Reverse /@ points]]

plot

Another method is to use Part:

ListPlot[points[[All, {2, 1}]]]

plot

It is interesting that RotateRight (or RotateLeft) is more efficient than Reverse but the fastest one is Part:

points = Table[{n, n^Sin[n]}, {n, 1, 10, 0.0000025}];

Reverse[points, 2]; // Timing
Reverse /@ points; // Timing
RotateRight[points, {0, 1}]; // Timing
points[[All, {2, 1}]]; // Timing    
{0.405603, Null}

{0.546004, Null}

{0.171601, Null}

{0.109201, Null}
points[[All, {2, 1}]] == RotateRight[points, {0, 1}] == Reverse[points, 2]
True
$\endgroup$

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