# ListPlot draws nothing

Consider the following simplified example:

data1 = {{{1, 1}, {8000, 1}}, {{1, 0}, {8000, 0}}};
data2 = {{{1, 1}, {10, 1}, {8000, 1}}, {{1, 0}, {8000, 0}}};
labels = {"L1", "L2"};
Row[ListLinePlot[MapThread[Tooltip, {#, labels}],
PlotRange -> All] & /@ {data1, data2},
BaseStyle -> ImageSizeMultipliers -> 1]


In the case of data1 ListLinePlot draws nothing! Addition of one point in the first dataset of data1 makes it working (data2).

Note that without Tooltip it works:

ListLinePlot[data1, PlotRange -> All]


Why ListLinePlot fails to draw the lines of data1 in the presence of the Tooltip wrapper? Is it a bug? Is there a workaround?

• i think this is related to the issue reported in this q/a: ListPlot does not plot Labeled data under some conditions
– kglr
May 25, 2018 at 13:48
• it seems that the issue arises more generally when individual datasets each contain two elements. For example, for d1={{{1, 1}, {8000, 1}},{{1, .5}, {8000, .5}}, {{1, 0}, {8000, 0}}} d2={{{1, 1},{2,1}, {8000, 1}},{{1, .5}, {8000, .5}}, {{1, 0}, {8000, 0}}} we get the same issue.
– kglr
May 25, 2018 at 14:11
• same issue with Style: that is, ListLinePlot[MapThread[Style, {#, {Red,Green}}], PlotRange -> All]& /@ {data1,data2}
– kglr
May 25, 2018 at 14:18
• I vote for bugs. You'd think symmetric cases (2x2) and extreme cases (2 points determine a line) would be in a test suite. (Have you reported it?) There is the ambiguity of a 2x2 array: is it two 1D datasets or one 2D dataset? (E.g. ListLinePlot[{{1, 2}, {3, 1}}], ListLinePlot[{{1, 2}, {2, 4}, {3, 1}}], ListLinePlot[{{1, 2, 4}, {3, 1, 4}}]) But I don't see how that would be related. May 25, 2018 at 15:11
• Definitely a bug. Reporting it. Jul 24, 2018 at 17:31

## 1 Answer

You are doing it a bit wrong. In your case the ListLinePlot is getting {{{1,1},{8000,1}},{{1,0},{8000,0}}} and {{{1,1},{10,1},{8000,1}},{{1,0},{8000,0}}} for plotting (use Echo for debugging, it's useful!), which doesn't make sense. One of the main problems you have in your code, is that any function (if it takes more than 1 argument), should get a sequence of arguments and not a list.

It's as simple as:

Row[ListLinePlot[Tooltip[Sequence @@ #]] & /@ Transpose[{{data1, data2}, labels}], BaseStyle -> ImageSizeMultipliers -> 1]


UPDATE

The Tooltip seems not to be responsive when you try to map it over data values when plotting. Here is an alternative solution, while I didn't figure out how to do exactly what you want:

Row[ListLinePlot[#, PlotLabels -> labels] & /@ {data1, data2}, BaseStyle -> ImageSizeMultipliers -> 1]


UPDATE

Ok, I think I have the solution you want:

ListLinePlot[{Tooltip[#[[1]], labels[[1]]], Tooltip[Prepend[#[[2]], {0, 0}], labels[[2]]]}] & /@ {data1, data2}


or

hackIt[data_] := ReplacePart[data, 2 -> Prepend[data[[2]], data[[2, 1]]]]

attachLabels[data_, label_] :=
MapThread[Tooltip[#1, #2] &,
{
data,
label
}
]

prepareData[data1_, data2_, labels_] :=
MapThread[attachLabels[hackIt[#1], #2] &,
{
{data1, data2},
Table[labels, 2]
}
]

ListLinePlot /@ prepareData[data1, data2, labels]


What happens here, is I duplicate the first point of the second line in each of data you have. Why is this required, I don't know (seems a bug to me).

• You wrap all the datasets by Tooltip at the top level, not the individual datasets. I need the upper line to have tooltip "L1" and the bottom line "L2". With your approach both lines have the same label. Jan 25, 2018 at 10:10