It is possible to make a Plot3D of a function $f(x,y)$, and to have the plot having its opacity $\alpha$ decrease as $x$ increases? For example say the plot has a range $x \in (0,10)$, and the opacity should be $\alpha = 1$ (fully non-transparent) for $x \in (0,8)$ and $\alpha = \frac{10-x}{2}$ for $x \in (8,10)$ (fully transparent at $x=10$).
$\begingroup$ $\endgroup$
Add a comment |
1 Answer
$\begingroup$ $\endgroup$
4 You can do this with ColorFunction:
Plot3D[x + y, {x, 0, 10}, {y, 0, 10}, ColorFunctionScaling -> False, ColorFunction -> (Opacity[If[# < 8, 1, (10 - #)/2], ColorData[97, 2]] &)] A couple of things to point out:
this is setting
ColorFunctionScaling -> Falseso that the formulas are in the form you specified them.you won't get the normal surface colors if your color function is just
Opacity, so I added the default color to the color function. One consequence it that you generally won't be able to do this with multiple functions in the same call toPlot3D.
- $\begingroup$ Nice, thanks a lot! If I were to use a color scheme such as "BlueGreenYellow", how would the syntax change? $\endgroup$Pxx– Pxx2021-12-09 16:44:47 +00:00Commented Dec 9, 2021 at 16:44
- 1$\begingroup$ Assuming coloring by height, Instead of
ColorData[97, 2]one way would be to changeColorData["BlueGreenYellow", #3]inside the color function and changeColorFunctionScaling -> {False, False, True}. If you want the fade and color to use the same parameters (x/y/z) then you might need to do some manual rescaling one way or the other. $\endgroup$Brett Champion– Brett Champion2021-12-09 16:51:29 +00:00Commented Dec 9, 2021 at 16:51 - $\begingroup$
Plot3D[x + y, {x, 0, 10}, {y, 0, 10}, ColorFunctionScaling -> False, ColorFunction -> (Opacity[If[# < 8, 1, (10 - #)/2], ColorData["BlueGreenYellow"][Rescale[#, {0, 10}]]] &)]$\endgroup$Bob Hanlon– Bob Hanlon2021-12-09 16:51:34 +00:00Commented Dec 9, 2021 at 16:51 - 1$\begingroup$ A hack-ish alternative is to use
Append[]on the color object resulting from e.g.ColorData["BlueGreenYellow"], which is effectively tacking on an extra alpha channel argument. Using Brett's example,Plot3D[x + y, {x, 0, 10}, {y, 0, 10}, ColorFunctionScaling -> False, ColorFunction -> (Append[ColorData[97, 2], If[# < 8, 1, (10 - #)/2]] &)]$\endgroup$J. M.'s missing motivation– J. M.'s missing motivation2021-12-09 18:26:18 +00:00Commented Dec 9, 2021 at 18:26
