# Opacity and Plot

I have the following function :

Plot[-2Cos[ Sqrt[50]/2 Sin[theta]] - 2,  {theta, 0, Pi/2},
PlotStyle -> Opacity[0.5], AxesLabel -> {θ, E[θ]}]


My problem is that I don't want a constant opacity (here 0.5) for this function but I want opacity as a function of theta (e.g : opacity = Sin[theta]) and I don't know how to do it with Mathematica. Is there a way to do this?

Geoffroy

Something like:

Plot[-2 Cos[Sqrt[50]/2 Sin[theta]] - 2, {theta, 0, Pi/2}, PlotStyle -> Thick,
ColorFunction -> (Opacity[Sin@#, Blue] &),
AxesLabel -> {\[Theta], E[\[Theta]]}]


You can also make the line color vary with theta while opacity varies with Sin@theta:

Plot[-2 Cos[Sqrt[50]/2 Sin[theta]] - 2, {theta, 0, Pi/2}, PlotStyle -> Thickness[.02],
ColorFunction -> (Opacity[Sin@#, ColorData["Rainbow"][#]] &),
AxesLabel -> {\[Theta], E[\[Theta]]}]


• In the first code block, shouldn't the ColorFunction option be just ColorFunction -> (Opacity[Sin@#, Blue] &)? – Taiki Feb 24 '15 at 14:11
• thank you Taiki -- cut/paste glitch. – kglr Feb 24 '15 at 14:13
• Thank you for your very quick answer kguler ! :) – Geoff Hudson Feb 24 '15 at 14:40
• @GeoffHudson, my pleasure. Welcome to mma.se. – kglr Feb 24 '15 at 14:42