2
$\begingroup$

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.

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}}} ]

wrong filling

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

$\endgroup$
1
  • 3
    $\begingroup$ I think this is a bug. You should report it to WRI. $\endgroup$
    – Michael E2
    Oct 27, 2020 at 23:07

1 Answer 1

3
$\begingroup$

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]}]

enter image description here

Alternatively, use FilledCurve instead of Polygon:

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

enter image description here

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}}]

enter image description here

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

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

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.