# A problem with correct filling for ListPlot and InterpolationOrder 0

Using ListPlot I can generate with

ListPlot[{{344.41, 272.2, 280}, {345, 223, 278}}, InterpolationOrder -> 0, PlotRange -> {200, 400}, Joined -> True]


a simple Plot.

However, if I now use a the "Filling" option Mathematica (12.1) displays the following wrong result.

ListPlot[{{344.41, 272.2, 280}, {345, 223, 278}}, InterpolationOrder -> 0, PlotRange -> {200, 400}, Joined -> True, Filling -> {1 -> {{2}, {Blue}}} ]


As far as I get it, the problem might arrise from the decimals. Is there a known solution for that?

• I think this is a bug. You should report it to WRI. Commented Oct 27, 2020 at 23:07

Two work-arounds:

1. Use ListPlot without the filling option and post-process the output to add the filling polygons as Epilog:

lp = ListPlot[{{344.41, 272.2, 280}, {345, 223, 278}},
InterpolationOrder -> 0, PlotRange -> {200, 400}, Joined -> True];

Show[lp,
Epilog -> {Opacity[.5, LightBlue],
Polygon @ Join[#, Reverse @ #2] & @@ Cases[lp, Line[x_, ___] :> x, All]}]


Alternatively, use FilledCurve instead of Polygon:

Show[lp,
Epilog -> {Opacity[.5, LightBlue],
FilledCurve @ ({#, Reverse /@ #2} & @@ Cases[lp, _Line, All])}]


2. Rationalizeing input data for some choice of the second argument also works:

ListPlot[Rationalize[{{344.41, 272.2, 280}, {345, 223, 278}}, 10^-2],
InterpolationOrder -> 0, PlotRange -> {200, 400}, Joined -> True,
Filling -> {1 -> {2}}]


Caveat: Need to automate the second argument of Rationalize based on input data.

• Interesting: if I use Rationalize[{{344.41, 272.2, 280}, {345, 223, 278}}, 10^-3] => at a higher order the problem is still there.
– StF
Commented Oct 27, 2020 at 23:29
• @StF, updated with caveats re the Rationalize approach.
– kglr
Commented Oct 28, 2020 at 0:08