8
$\begingroup$

I have two sets of x,y coordinates, and want to plot them both on the same graph. With one set,

List1 $= \{ \{ x_1, y_1 \}, \{ x_2, y_2 \},\{ x_3, y_3 \}, \cdots \}$

I can use ListLinePlot[List1].

But with a second list,

List2 $= \{ \{ u_1, v_1 \}, \{ u_2, v_2 \},\{ u_3, v_3 \}, \cdots \}$

I assumed I'd be able to use something like ListLinePlot[List1,List2], but this seems reserved for when the lists have only one of the coordinates: $\{ x_1, x_2, x_3, \cdots\}$.

The data in List1 has to be connected via a line, as does the data in List2, but they mustn't be joined together (i.e. I can't amalgamate them into one list). Anyone know how I can plot both sets on the same graph?

$\endgroup$
4
  • 1
    $\begingroup$ The answer is the third syntax form on the ListLinePlot doc page. If you have questions in the future, could you please check the reference pages first? $\endgroup$ Mar 12, 2012 at 0:24
  • $\begingroup$ @SjoerdC.deVries I did! I made the mistake of thinking the curly brackets outside each list $\{ \{ x_1, y_1 \}, \cdots \}$ were the same curly brackets as in the 3rd form of ListLinePlot in the documentation, so I was short of the outside set of brackets. $\endgroup$
    – Calvin
    Mar 12, 2012 at 22:30
  • $\begingroup$ Yeah, that is quite understandable. The docs have the habit of summarizing earlier syntax constructions that are being reused in forms later on into a single word (not formally defined). So, {{x1,y1},⋯} becomes list1. It happens all the time and it takes some getting used to it. Apologies if I sounded rude. $\endgroup$ Mar 12, 2012 at 22:36
  • $\begingroup$ @SjoerdC.deVries No worries, thank for your comment. Hopefully I'll get used to it soon :o) $\endgroup$
    – Calvin
    Mar 14, 2012 at 22:04

2 Answers 2

14
$\begingroup$

Instead of ListLinePlot[ list1, list2 ] use ListLinePlot[ {list1, list2} ].

$\endgroup$
3
  • $\begingroup$ Awesome - thanks. Seems so obvious now! $\endgroup$
    – Calvin
    Mar 11, 2012 at 2:52
  • $\begingroup$ @Calvin To the best of my knowledge, every plotting function operates that way. So, if you need to plot multiple things on a single plot, just wrap them in a list. $\endgroup$
    – rcollyer
    Mar 11, 2012 at 2:55
  • $\begingroup$ One exception is the PairedXXXX set of functions. Although in that case it perhaps depends on your interpretation of "single plot". $\endgroup$ Mar 11, 2012 at 2:57
3
$\begingroup$

Or

p1=ListLinePlot[list1, PlotStyle -> {DotDashed, Thick}, PlotLegends -> {"list1"}];
p2=ListLinePlot[list2, PlotStyle -> {Dashed, Black}, PlotLegends -> {"list2"}];
Show[p1,p2]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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