5
$\begingroup$
Plot[1 - x^2, {x, -1.5, 1.5},
 Filling -> Axis, FillingStyle -> {None, Automatic}]

produces an outcomes I find unexpected:

unexpected fill

In contrast,

Plot[1 - x^2, {x, -1.5, 1.5},
 Filling -> Axis, FillingStyle -> {None, LightBlue}]

produces the expected outcome:

expected fill

Have I misunderstood the meaning of Automatic in this setting? That is, why would I not see the same area shaded in both cases?

$\endgroup$

3 Answers 3

4
$\begingroup$

It appears to me that Automatic is not a valid input at that level of the option specification. Consider that this generates the same output:

Plot[1 - x^2, {x, -1.5, 1.5}
 , Filling -> Axis
 , FillingStyle -> {None, "bad input"}
]

enter image description here


Spelunking

I was not able to find any great revelations, but since Alan wrote: "But I'm hoping Mr. Wizard will still offer some insights as to why we would be driven to such hackishness" I thought I should at least try to look at the implementation behind this behavior. I used PrintDefinitions from the GeneralUtilities package and Trace. From:

Needs["GeneralUtilities`"]
PrintDefinitions @ System`ProtoPlotDump`iPlot

I found that (in version 10.1.0) the FillingStyle option value is handed off (as fillingstyle) to the internal function Charting`customFillingStyle with the call:

If[filling === None, None, 
 Charting`customFillingStyle[filling, plotstyle, defaultstyle, fillingstyle, 
   System`ProtoPlotDump`$FillingStyleOpacity][Length[modelData["Expressions"]], 
  Plot]]

Spelunking that (PrintDefinitions @ Charting`customFillingStyle) reveals definitions for explicit Automatic arguments which would not match {None, Automatic}, e.g.:

Charting`customFillingStyle[Automatic | Axis, Charting`CommonDump`pstyle_, 
  Charting`CommonDump`dpstyle_, Automatic, Charting`CommonDump`opacity_] := . . .

Other values are again handed off, this time to as the second parameter of Charting`CommonDump`combinePnFStyle. Reading that definition (PrintDefinitions @ Charting`CommonDump`combinePnFStyle) shows that this function is expecting a color (_?ColorQ) or Graphics directive (_?Charting`generalDirective), or a List which contains either colors, directives, or None, e.g. {_?(MatchQ[#1, Except[_Rule, _?ColorQ | None]] &) ..}. There is no provision for Automatic at this level of the program. If the argument does not match one of the patterns above is effectively dropped by the final definition in which the second parameter is unnamed and unused:

Charting`CommonDump`combinePnFStyle[_, _, opacity_, i_] := 
  Charting`padList[
   Charting`ConstructDirective[ColorData[1][i], 
    If[opacity === {}, {}, Opacity[opacity]]], 2];

What I first wrote is borne out: Automatic is not a valid input as the element of a List within the option value of FillingStyle; it is only valid as the complete option value. I cannot explain this design choice, only offer this analysis of the existing program code. Using FillingStyle -> {None, Opacity[0.2]} may seem like a hack but it is concise and effective.

$\endgroup$
7
  • 1
    $\begingroup$ Yes. i. Does it seem "right" that Automatic would be invalid here? ii. How then is one supposed to get the current default fill color? $\endgroup$
    – Alan
    Commented Sep 30, 2016 at 10:16
  • $\begingroup$ @Alan Let me think about both points and get back to you. $\endgroup$
    – Mr.Wizard
    Commented Sep 30, 2016 at 10:20
  • $\begingroup$ @Alan Although a bit award, Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, Directive[ColorData[97], Opacity[.2]]}]`, seems to work. $\endgroup$
    – bbgodfrey
    Commented Sep 30, 2016 at 14:14
  • $\begingroup$ @Alan Or, Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, Opacity[.2]}] $\endgroup$
    – bbgodfrey
    Commented Sep 30, 2016 at 14:30
  • $\begingroup$ @bbgodfrey Thanks for pointing out the opacity hack. (Also to Edmund and Chip.) But I'm hoping Mr. Wizard will still offer some insights as to why we would be driven to such hackishness. $\endgroup$
    – Alan
    Commented Sep 30, 2016 at 18:29
3
$\begingroup$

To get the current colour you can hack it with FillingStyle -> {Opacity[0], Opacity[1]}.

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {Opacity[0], Opacity[1]}]

Mathematica graphics

Hope this helps.

$\endgroup$
1
  • 2
    $\begingroup$ I think you want {Opacity[0], Opacity[0.2]} to get the default result. $\endgroup$
    – Greg Hurst
    Commented Sep 30, 2016 at 14:18
1
$\begingroup$
Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, LightGray}]

fills None below the axis and LightGrey above the axis, as shown in the question.

On the other hand, Automatic seems to override None in

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, Automatic}]

causing a Filling of Blue throughout, just as in

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {Automatic}]

To obtain LightGrey throughout, use

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> LightGray]

enter image description here

or to obtain Blue only in the center section, use

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, Blue}]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ My question is whether there is a bug in the handling of Automatic, or have I misunderstood it somehow. $\endgroup$
    – Alan
    Commented Sep 30, 2016 at 9:17
  • $\begingroup$ Apparently, anything combined with Automatic yields the first plot in your question,.for instance, FillingStyle -> {Red, Automatic}. I would call this a bug, but others might describe it simply as inadequate documentation. $\endgroup$
    – bbgodfrey
    Commented Sep 30, 2016 at 12:43
  • $\begingroup$ Note that Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {Red, White, Blue}] also yields the first plot in your question. This suggests that any instance of incorrect syntax reverts to {Automatic}. Perhaps, FillingStyle considers {None, Automatic} as bad syntax, although the documentation does not say so. $\endgroup$
    – bbgodfrey
    Commented Sep 30, 2016 at 12:52

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.