11
$\begingroup$

Bug introduced in 11.2 or earlier and persisting through 12.0


There are something wrong when I try to evaluate the example from Lighting Docs, here is the code:

lights = {{"Spot", Red, {{3, 3, 5}, {3, 3, 0}}, Pi/8}, {"Spot", Green, {{7, 3, 5}, {7, 3, 0}}, Pi/8}, {"Spot", Blue, {{5, 6, 5}, {5, 6, 0}}, Pi/8}}; 

plane = ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False];  

Show[plane, Lighting -> lights]  

Unfortunately it does not work as expected in Mathematica version 11.3.
But if we directly use the form

ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False,Lighting->lights]  

it works.

So I want to know the reason for creating the different outcome, may be researching the InputForm of output seems a feasible point, but I failed. Thanks for any info on this matter.

$\endgroup$
  • $\begingroup$ Same behavior in v11.2. Works as expected in v9.0.1. $\endgroup$ – xzczd Feb 17 at 4:42
9
$\begingroup$

Update: This is yet another case of automatic PlotTheme settings injecting directives that override the user-specified ones. So, a much easier fix is to add the option PlotTheme -> None to ParametricPlot3D.

plane = ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, 
   PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False, 
   PlotTheme -> None];

Show[plane, Lighting -> lights]

enter image description here

Note: You can find a number of other issues fixed by explicitly removing PlotTheme on this page.

Original answer:

I think this is a bug.

A fix is to remove Lighting from plane before using it in Show:

plane = ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, 
   PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False, ImageSize -> 300];
planeb = DeleteCases[plane, Lighting -> _, All];
Grid[Labeled[ToExpression@#, #, Top] & /@ # & /@ 
 {{"plane", "Show[plane,Lighting->lights]"},
  {"planeb", "Show[planeb,Lighting->lights]"}}]

enter image description here

What I think is happening:

The lighting settings from the default PlotTheme -> Automatic are embedded as directives before graphics primitives in ParametricPlot3D. This can be verified using

Cases[plane, {a : ___, l : (Lighting -> _), ___} :> {a, l}, All]

enter image description here

or using

Cases["DefaultPlotStyle" /. (Method /. 
  Charting`ResolvePlotTheme[Automatic, ParametricPlot3D]), HoldPattern[Lighting -> _], All]

enter image description here

As noted by xzczd in comments, this issue does not arise in version 9:

Labeled[Row[Labeled[ToExpression@#, #, Top] & /@ {"plane", 
    "Show[plane,Lighting -> lights]"}], "Version: " <> $Version]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.