Skip to main content
added 134 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

data = Sort[{{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, Missing[]}, {8, 4}, {10, 3}, {10, 2}, {11, 1}}]; (* Sort to make sure data is ordered prior to interpolation *)

(data[[#]] = {data[[#, 1]], Interpolation[ {data[[# - 1]], data[[# + 1]]}][data[[#, 1]]]}) & /@ Flatten[Position[data, {_, Missing[]}]]; // Quiet

Note that ListLinePlot does not need to use Joined option

ListLinePlot[data, Filling -> Axis, GridLines -> Automatic, Mesh -> Full, PlotMarkers -> Automatic, InterpolationOrder -> 2]

data = Sort[{{1, 1}, {2, 2}, {3, Missing[]},
    {4, 4}, {5, 5}, {6, 6}, {7, Missing[]},
    {8, 4}, {10, 3}, {10, 2}, {11, 1}}];
(* Sort to make sure data is ordered prior to interpolation *)

(data[[#]] = {data[[#, 1]],
       Interpolation[
         {data[[# - 1]], data[[# + 1]]}][data[[#, 1]]]}) & /@ 
   Flatten[Position[data, {_, Missing[]}]]; // Quiet

Note that ListLinePlot does not need to use Joined option

ListLinePlot[data,
 Filling -> Axis,
 GridLines -> Automatic,
 Mesh -> Full,
 PlotMarkers -> Automatic,
 InterpolationOrder -> 2]

If the data does not include repeated x values (e.g., {..., {10, 3}, {10, 2}, ...}), delete missing data, interpolate, and use Plot.

data = {{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, Missing[]}, {8, 4}, {10, 3}, {11, 1}};

data = DeleteCases[data, {_, Missing[]}];

f = Interpolation[data, InterpolationOrder -> 2];

Plot[f[x], {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}, AxesOrigin -> {0, 0}, Filling -> Axis, GridLines -> Automatic, Epilog -> {AbsolutePointSize[6], Point[data]} ]

data = {{1, 1}, {2, 2}, {3, Missing[]},
   {4, 4}, {5, 5}, {6, 6}, {7, Missing[]},
   {8, 4}, {10, 3}, {11, 1}};

data = DeleteCases[data, {_, Missing[]}];

f = Interpolation[data, InterpolationOrder -> 2];

Plot[f[x],
 {x, Min[data[[All, 1]]], Max[data[[All, 1]]]},
 AxesOrigin -> {0, 0},
 Filling -> Axis,
 GridLines -> Automatic,
 Epilog -> {AbsolutePointSize[6], Point[data]}
 ]

data = Sort[{{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, Missing[]}, {8, 4}, {10, 3}, {10, 2}, {11, 1}}]; (* Sort to make sure data is ordered prior to interpolation *)

(data[[#]] = {data[[#, 1]], Interpolation[ {data[[# - 1]], data[[# + 1]]}][data[[#, 1]]]}) & /@ Flatten[Position[data, {_, Missing[]}]]; // Quiet

Note that ListLinePlot does not need to use Joined option

ListLinePlot[data, Filling -> Axis, GridLines -> Automatic, Mesh -> Full, PlotMarkers -> Automatic, InterpolationOrder -> 2]

If the data does not include repeated x values (e.g., {..., {10, 3}, {10, 2}, ...}), delete missing data, interpolate, and use Plot.

data = {{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, Missing[]}, {8, 4}, {10, 3}, {11, 1}};

data = DeleteCases[data, {_, Missing[]}];

f = Interpolation[data, InterpolationOrder -> 2];

Plot[f[x], {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}, AxesOrigin -> {0, 0}, Filling -> Axis, GridLines -> Automatic, Epilog -> {AbsolutePointSize[6], Point[data]} ]

data = Sort[{{1, 1}, {2, 2}, {3, Missing[]},
    {4, 4}, {5, 5}, {6, 6}, {7, Missing[]},
    {8, 4}, {10, 3}, {10, 2}, {11, 1}}];
(* Sort to make sure data is ordered prior to interpolation *)

(data[[#]] = {data[[#, 1]],
       Interpolation[
         {data[[# - 1]], data[[# + 1]]}][data[[#, 1]]]}) & /@ 
   Flatten[Position[data, {_, Missing[]}]]; // Quiet

Note that ListLinePlot does not need to use Joined option

ListLinePlot[data,
 Filling -> Axis,
 GridLines -> Automatic,
 Mesh -> Full,
 PlotMarkers -> Automatic,
 InterpolationOrder -> 2]

If the data does not include repeated x values (e.g., {..., {10, 3}, {10, 2}, ...}), delete missing data, interpolate, and use Plot.

data = {{1, 1}, {2, 2}, {3, Missing[]},
   {4, 4}, {5, 5}, {6, 6}, {7, Missing[]},
   {8, 4}, {10, 3}, {11, 1}};

data = DeleteCases[data, {_, Missing[]}];

f = Interpolation[data, InterpolationOrder -> 2];

Plot[f[x],
 {x, Min[data[[All, 1]]], Max[data[[All, 1]]]},
 AxesOrigin -> {0, 0},
 Filling -> Axis,
 GridLines -> Automatic,
 Epilog -> {AbsolutePointSize[6], Point[data]}
 ]
Source Link
Bob Hanlon
  • 162.6k
  • 7
  • 81
  • 205

Fill in the missing values by interpolation. The following simple example does not handle all cases (e.g., consecutive missing values).

data = Sort[{{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, Missing[]}, {8, 4}, {10, 3}, {10, 2}, {11, 1}}]; (* Sort to make sure data is ordered prior to interpolation *)

(data[[#]] = {data[[#, 1]], Interpolation[ {data[[# - 1]], data[[# + 1]]}][data[[#, 1]]]}) & /@ Flatten[Position[data, {_, Missing[]}]]; // Quiet

Note that ListLinePlot does not need to use Joined option

ListLinePlot[data, Filling -> Axis, GridLines -> Automatic, Mesh -> Full, PlotMarkers -> Automatic, InterpolationOrder -> 2]

If the data does not include repeated x values (e.g., {..., {10, 3}, {10, 2}, ...}), delete missing data, interpolate, and use Plot.

data = {{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, Missing[]}, {8, 4}, {10, 3}, {11, 1}};

data = DeleteCases[data, {_, Missing[]}];

f = Interpolation[data, InterpolationOrder -> 2];

Plot[f[x], {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}, AxesOrigin -> {0, 0}, Filling -> Axis, GridLines -> Automatic, Epilog -> {AbsolutePointSize[6], Point[data]} ]

Bob Hanlon