l1={1,2,3,4}
l2={5,6,7,8}
I want to plot the l2 against l1. that is at value 1 on x axis, it should show value 5, 6 at value 2 and so on..how can i do that?
ListPlot can be used to plot lists of discrete points. The documentation notes that to specify both abscissa, as well as the ordinate, for your points then the supplied list must be of the form $\{\{x_1,y_1\},\dotsc,\{x_n,y_n\}\}$. So we can
{l1,l2}
to obtain the form $\{\{x_1,\dotsc,x_2\},\{y_1,\dotsc,y_n\}\}$, then transpose it to get the necessary form. In one shot,
l1={1,2,3,4}
l2={5,6,7,8}
ListPlot[Transpose@{l1,l2}]
To see why Transpose dose that job, you can run the following code:
l1 = {1, 2, 3, 4} ;
l2 = {5, 6, 7, 8};
{l1, l2} // MatrixForm
l3 = Transpose[{l1, l2}];
l3 // MatrixForm
ListPlot[l3,
Joined -> True](*Set to False if you want the discrete points*)
Joined->False is the default for ListPlot. It does no harm but is not needed.
– Jack LaVigne
Nov 02 '15 at 03:16
ListPlot[Transpose@{l1,l2}]– IPoiler Nov 02 '15 at 02:00