# Plotting a list against a list [duplicate]

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?

## marked as duplicate by Kuba♦, J. M. is away♦Nov 2 '15 at 8:19

• ListPlot[Transpose@{l1,l2}] – IPoiler Nov 2 '15 at 2:00
• @IPoiler that's a legit answer; you should post it as one. – Pillsy Nov 2 '15 at 2:05
• I'm quite sure this is a dupe. – J. M. is away Nov 2 '15 at 2:46
• @J.M. yep, it is, maybe some additional key words are needed – Kuba Nov 2 '15 at 8:14
• Now, that didn't show up in my searches. Thanks @Kuba! – J. M. is away Nov 2 '15 at 8:16

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 2 '15 at 3:16
• @JackLaVigne I just want to show OP an option. – 喵喵是我的猫猫 Nov 2 '15 at 3:41