I have just created a 3D surface plot with the function Plot3D. Now, I want to change the opacity of the graph, after I have created it, without having to redraw the graph.

I am able to change things like axislabels etc., but I cannot find how I can change the opacity after creation.

Is this possible?

  • 3
    $\begingroup$ Does Show[plot, BaseStyle -> Opacity[.5]] work for you? $\endgroup$ – Carl Woll Aug 15 '17 at 20:01
  • $\begingroup$ That works great! What if I use the function Show[plot1,plot2] and I only want to change the opacity of plot1? If I use Show[plot1, plot1, BaseStyle -> Opacity[.5]], both plots get Opacity 0.5. $\endgroup$ – Peter Lawrence Aug 15 '17 at 20:17
  • $\begingroup$ Peter, BaseStyle affects everything that is not explicitly styled, so by nature it will affect both plots; there can be only one BaseStyle for the combined Graphics3D expression. Working with the primitives is more flexible. $\endgroup$ – Mr.Wizard Aug 15 '17 at 20:20
  • 2
    $\begingroup$ @anderstood No, that actually doesn't work because only one BaseStyle directive is retained. $\endgroup$ – Mr.Wizard Aug 15 '17 at 20:28
  • 1
    $\begingroup$ Changing a color is harder as you have to replace a directive that already exists in the plot. The method used may need to change depending on the source of the plot. For the example I chose we can use something as simple as plot /. _Directive :> Opacity[.5, Red] $\endgroup$ – Mr.Wizard Aug 15 '17 at 20:37

To affect the primitives only and not the frame, labels, etc.:

plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]

plot // MapAt[{Opacity[0.5], #} &, 1]

enter image description here


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.