# Peculiar behaviour in the implementation of “Filling”

I was working with mathematica and I need to use "Filling", however I notice that it doesn't work when you have "small" numbers, for example if I make the following:

Plot[Evaluate[{x + 1, x + 2}], {x, -1*10^-15,1*10^-15},PlotRange -> All, Filling -> {1 -> {2}}]


The "Filling" doesn't appears.

Question

There is some way to make that the "Filling" appear?

Extra

Since this question appear in a physical context, I know that I can change units in order to make "x" a larger number.(Actually I do this.)

• Try Filling -> {1 -> 2}. – Rohit Namjoshi Jun 29 '20 at 0:13
• I tried it, however it "seems" that only work in some cases. Try Plot[Evaluate[{1*10^15 (x) - 1, (1*10^15) x + 1}], {x, -1*10^-15, 1*10^-15}, PlotRange -> All, Filling -> {1 -> 2}] It seems that doesn't work – No name Jun 29 '20 at 0:34
• @RohitNamjoshi I'd say that Filling -> {1 -> {2}} would be perfectly correct to fill between the first and second plot rather thatn to the value $2$. It should work. Indeed, if you plot over the {x, -1*^-14, 1*^-14} range, you will see the filling just fine. I think OP is right that this is weird behavior... – MarcoB Jun 29 '20 at 1:31
• It's a numerical issue. Change 10^-15 to 10^-5 and it works as you would expect. Presumably the "filling" part of the plot command is using floating point numbers. – bill s Jun 29 '20 at 16:31
• I was unable to find a way to peer into the internals to look for the problem or a way to patch it. Are you interested in functional work-arounds, like rescaling your plot function and changing the axis labels automatically? – Mr.Wizard Jul 2 '20 at 1:14

## 1 Answer

There are two perspectives in the question

a) PlotRange -> All b) Filling -> {1 -> {2}}

to a)

It is necessary to put in both intervals explicitly into the options of PlotRange:

PlotRange -> {{-1.*10^-15, 1.*10^-15}, {-1.0, 2.1}}


will present the desired result.

to b)

This appears to me as taken from the example for Filling Fill between curves 1 and 2.

I agree this example works for me too. I am using 12.0.

And I get

Plot[{x + 1, x + 2}, {x, 0, 2 Pi}, Filling -> {1 -> {2}}] This even can not be narrowed in the interval!!! And the built-in Evaluation does not change anything.

The cause can be in the invalid options since with Filling -> {1 -> 2} the plot became as expected:

Plot[Evaluate[{x + 1, x + 2}], {x, -1.*10^-15, 1.*10^-15},
Filling -> {1 -> 2},
PlotRange -> {{-1.*10^-15, 1.*10^-15}, {-1.0, 2.1}}] Mind the example is listed under the section Filling Limits in the Mathematica documentation for Filling.

The curly brackets are suggested for the use with style options or if there are more curves or sections of the interval with separate fillings in the section Details.

Most probable the reason stems from the granularity of the option in the example. Plot in Mathematica uses an interval division algorithm to represent curve smoothly. This algorithm works brilliantly for example trigonometric functions but fails if the given interval is to narrow and the first derivative of the function to be displayed is to small.

In the given case both are about the same interval length and magnitude of the first derivative of the linear function over the interval for interpolation. Since the interpolation is already exact Mathematica does not further refine the representation and the filling algorithm fails. This process is shown in the documentation for Plot in the section Details and Options.

Since the example is given without commending this is transferred into the knowledge of the Mathematica user. So the question is to be dealt with respect, but very basic knowledge.

This question make $MachinePrecision as the interval length and change rate of the function. $MachinePrecision


15.9546

The limit is different on each machine:

\$MinMachineNumber


2.22507*10^-308

for example on mine.

So setting MaxRecursion bigger than 15 fails in this case. This option limits the efforts of refine the curvature to appear smooth to the human eye.

The option Mesh show the efforts already in the seemingly failed example:

Plot[{SetPrecision[x + 1., MachinePrecision],
SetPrecision[x + 2., MachinePrecision]}, {x,
SetPrecision[-1.000*10^-15, MachinePrecision],
SetPrecision[1.000*10^-15, MachinePrecision]},
Filling -> {1 -> {2}}, Mesh -> All] Some variation that works is

ListPlot[{Table[x + 1, {x, -1*10^-15, 1*10^-15, 2*10^-16}],
Table[x + 2, {x, -1*10^-15, 1*10^-15, 2*10^-16}]}, Joined -> True,
Filling -> {1 -> {2}}, Axes -> True,
DataRange -> {-1*10^-15, 1*10^-15}] ListPlot[{Table[x + 1, {x, -1*10^-15, 1*10^-15, 2*10^-16}],
Table[x + 2, {x, -1*10^-15, 1*10^-15, 2*10^-16}]}, Joined -> True,
Filling -> {1 -> {2}}, Axes -> True] ListPlot[{Table[{x, x + 1}, {x, -1*10^-15, 1*10^-15, 2*10^-16}],
Table[{x, x + 2}, {x, -1*10^-15, 1*10^-15, 2*10^-16}]},
Filling -> {1 -> {2}}] ListPlot[{Table[{x, x + 1}, {x, -1*10^-15, 1*10^-15, 2*10^-16}],
Table[{x, x + 2}, {x, -1*10^-15, 1*10^-15, 2*10^-16}]},
Joined -> True, Filling -> {1 -> {2}}] Design own plot primitives to workaround or accept what is possible.

gg = Graphics[{Opacity[0.3], LightGray,
Rectangle[{-10^-15, 1}, {10^-15, 2}]}, Axes -> True,
AspectRatio -> 1/3,
PlotRange -> {{-1.*10^-15, 1.*10^-15}, {.0, 2.1}}] Show[Plot[Evaluate[{x + 1, x + 2}], {x, -1*10^-15, 1*10^-15},
PlotRange -> {{-1.*10^-15, 1.*10^-15}, {-1.0, 2.1}}], gg] 