2
$\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$

closed as off-topic by march, zhk, Bob Hanlon, m_goldberg, MarcoB Aug 31 '17 at 4:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – march, zhk, Bob Hanlon, m_goldberg, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 8
    $\begingroup$ ListPlot[Reverse[points, 2]] or something like it should be useful. $\endgroup$ – J. M. will be back soon Aug 30 '17 at 17:10
  • $\begingroup$ Thanks! Solved. $\endgroup$ – Mateus Aug 30 '17 at 17:13
2
$\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.