The following code produces a ListPlot correctly, except that the tooltip does not work for the last data point.

testData = {{.5, 1}, {.6, 1}, {None, None}, {.601, .5}, {.7, 0}, {None, None}, {.9, 0}, {1, .4}};
ListPlot[Tooltip[testData], Joined -> True, Mesh -> Full]

If either pair of Nones is removed, it works fine, but I would like to break the line joining the data in specific places so that the line appears as three separate segments. I could turn the list into three separate lists, but I want the plot style to be the same for each of the segments, and it would be a pain to specify this using PlotStyle because in practice I am plotting several data sets simultaneously, each with breaks in the same places, and I want each data set to appear with a distinct style (but the three segments within each data set should match each other).

One option that seems to work is to use Blank instead of None for one pair of {None, None}. If using it for both pairs, the same issue occurs. But then the issue appears again if I add a fourth separate segment to the same data list. So, is there a less hacky fix?


1 Answer 1


(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)


testData = {
   {{.5, 1}, {.6, 1}, {None, None}, {.601, .5}, {.7, 0}, {None, 
     None}, {.9, 0}, {1, .4}},
   {{.5, .9}, {.6, .8}, {None, None}, {.601, .25}, {.7, .1}, {None, 
     None}, {.9, 0}, {1, .6}}};

testData2 = (Split[#, FreeQ[#, None] &] & /@ testData) /.
   {None, None} :> Nothing;

  ListLinePlot[Tooltip /@ #1,
    PlotStyle -> ColorData[97][#2[[1]]]] &,

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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