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.
Null
instead ofMissing[]
? 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. $\endgroup$Null
does not work either (it works in that it removes the data and leaves lines disconnected. But it does not work withInterpolationOrder -> 2
). $\endgroup$