# Making a plot from three lists [closed]

I have data like

x = [1, 2, 3, 4, 5, 6, 7, 8, 9]

and

y1 = [0, 11, 12, 13, 14, 15, 16, 17]

and

y2 = [0, 10, 11.5, 12.5. 13.5, 14.5]

I want to plot y1} and y2} as a function of x on one plot and then draw a vertical line at x = 12 like a Kronecker delta.

How can I do this?

• Would you please present your data in Mathematica format, i.e. as a list delimited by curly braces { }? Normally, Transpose@{x,y1} would give you a dataset you could plot using ListPlot, as was pointed out to you in your previous question. However, your data sets have different lengths, so that wouldn't work. Do you really have to deal with different-length lists? – MarcoB Feb 6 '17 at 6:55
• Your data is inconsistent. You have 9 x values, and only 8 y1 values. I can't read y2. Any way, check ListLinePlot and check Show to combine. And check Line to make line. – Nasser Feb 6 '17 at 6:56
• @MarcoB no i can do my work by equal length data – Ehsan F Feb 6 '17 at 7:31
• @MarcoB how plot this?x=[1,2,3,4,5,6,7,8] and y(1)=[0,11,12,13,14,15,16,17] and y(2)=[0,10,11.5,12.5.13.5,14.5,15.2,16] and a vertical line at x=12 – Ehsan F Feb 6 '17 at 7:36
• @EhsanF Your sets are still of different length; y2 is too short by one. Also, lists are enclosed by curly brances in MMA, e.g. x = {1, 2, 3, 4, 5, 6, 7, 8}. Try ListLinePlot@Transpose@{x1, y1}. – MarcoB Feb 6 '17 at 7:40

I think your example is ill-considered, but the following does what you ask.

x = {1, 2, 3, 4, 5, 6, 7, 8, 9};
y1 = {0, 11, 12, 13, 14, 15, 16, 17};
y2 = {0, 10, 11.5, 12.5 .13 .5, 14.5};

ListLinePlot[{y1, y2},
PlotRange -> {{0, 13}, Automatic},
GridLines -> {{12}, None}]


Now, let's look at a more realistic case.

SeedRandom[42]; x = RandomSample[Range[15], 9] // Sort


{1, 3, 7, 9, 10, 12, 13, 14, 15}

y1 = {0, 11, 12, 13, 14, 15, 16, 17, 18};
y2 = {0, 10, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5};


Then the data can be prepared for plotting with

data = MapThread[{{#1, #2}, {#1, #3}} &, {x, y1, y2}] // Transpose

{{{1, 0}, {3, 11}, {7, 12}, {9, 13}, {10, 14}, {12, 15}, {13, 16}, {14, 17},
{15, 18}},
{{1, 0}, {3, 10}, {7, 11.5}, {9, 12.5}, {10, 13.5}, {12, 14.5}, {13, 15.5},
{14, 16.5}, {15, 17.5}}}


and the plot can be made with

ListLinePlot[data, GridLines -> {{12}, None}]