# Interpolation impossible for ListPlot with Missing?

I have a list of data to plot. I would like to plot them with lines but delete some data before plotting and leave the lines disconnected where data is deleted. For example,

ListPlot[Sin[0.5 Range@100] /. {a_?Negative -> Missing[]}, Joined -> True]


This works well. However, the data is not dense enough to make smooth plots. Thus I want to turn on interpolation:

ListPlot[Sin[0.5 Range@100] /. {a_?Negative -> Missing[]},
Joined -> True, InterpolationOrder -> 2]


However, This ends up with en error message and the same figure without interpolation.

ListPlot::ioproc: "{{1.,0.479426},{2.,0.841471},{3.,0.997495},{4.,0.909297},{5.,0.598472},{6.,0.14112},<<39>>,{46.,Missing[]},{47.,Missing[]},{48.,Missing[]},{49.,Missing[]},{50.,Missing[]},<<50>>} may contain non-machine-precision numbers, complex numbers, or invalid entries."

I think to set the data points to Missing[] should be the right way to remove data. Thus is it a bug that the data fail to interpolate?

I would have first interpolated data by hand using

Interpolation[data] /@
Range[Min[data[[All, 1]]], Max[data[[All, 1]]],
(Max[data[[All, 1]]] - Min[data[[All, 1]]] + 1)/(10.*Length[data])]


and send the result to ListPlot. But let me still ask this question because I thought InterpolationOrder -> 2 should work but it didn't.

-
Have you tried Null instead of Missing[]? I'm not near a computer with Mathematica to check, but this works for me in other contexts. But you will probably still need to index the data. –  Verbeia Apr 11 '14 at 15:13
@Verbeia : Thanks for your comment. Unfortunately Null does not work either (it works in that it removes the data and leaves lines disconnected. But it does not work with InterpolationOrder -> 2). –  Yi Wang Apr 11 '14 at 15:17

I can't think of a way to do this without indexing the data. If that's not a problem, the following will do:

    With[{
indexed = MapIndexed[
{Sequence @@ #2, #1} &,
Sin[0.5 Range@100] /. {a_?Negative -> Missing[]}
]
},
ListPlot[
SplitBy[
indexed,
NumericQ@Last@# &
],
Joined -> True,
InterpolationOrder -> 2
]
]
(* Some errors spat out in trying to interpolate a series of Missing bits*)


-
Thanks for the answer! My work around currently is to first interpolate data. Your answer provides another interesting work around :) –  Yi Wang Apr 11 '14 at 11:13

You could just do without Missing:

ListPlot[Cases[{#, Sin[0.5 #]} & /@ Range[100], {_, _?NonNegative}],
Joined -> True]


-
Thanks a lot for the answer! However, this is exactly what I would tried to avoid. I want to break the lines where the data have been deleted. And my problem arises because of this requirement. –  Yi Wang Apr 11 '14 at 9:35
@YiWang ok. Sorry –  ubpdqn Apr 11 '14 at 10:58