5
$\begingroup$

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?

Thank you in advance for your time.

Geoffroy

$\endgroup$
8
$\begingroup$

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]]}]

enter image description here

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]]}]

enter image description here

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

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.