2
$\begingroup$

We have the bellow plot:

Plot[Sin[2 x]^2 Cos[1/2 x]^2, {x, 0, 2 \[Pi]}, 
PlotStyle -> {{Thickness[0.008], AbsoluteDashing[{15, 4, 4, 5}]}}]

The desired case is to have a plot that the part of the plot near the horizontal line be Darker than higher ones (which are lighter) (as gradient). However I saw some examples for gradient plots in SE but they are for multi-plots not for just one plot.

$\endgroup$
9
$\begingroup$
Plot[Sin[2 x]^2 Cos[1/2 x]^2, {x, 0, 2 \[Pi]},
 ColorFunction -> (Blend[{Blue, Yellow}, #2] &),
 ColorFunctionScaling -> False,
 GridLines -> Automatic,
 PlotStyle -> {{Thickness[0.008], AbsoluteDashing[{15, 4, 4, 5}]}}]

enter image description here

Some other possibilities:

Plot[Sin[2 x]^2 Cos[1/2 x]^2, {x, 0, 2 \[Pi]},
 ColorFunction -> Function[{x, y}, If[y > 0.2, Red, Black]],
 ColorFunctionScaling -> False,
 GridLines -> Automatic,
 PlotStyle -> {{Thickness[0.008], AbsoluteDashing[{15, 4, 4, 5}]}}]

enter image description here

Plot[Sin[2 x]^2 Cos[1/2 x]^2, {x, 0, 2 \[Pi]},
 ColorFunction -> Function[{x, y}, GrayLevel@y],
 ColorFunctionScaling -> False,
 GridLines -> Automatic,
 PlotStyle -> {{Thickness[0.008], AbsoluteDashing[{15, 4, 4, 5}]}}]

enter image description here

Plot[Sin[2 x]^2 Cos[1/2 x]^2, {x, 0, 2 \[Pi]},
 ColorFunction -> "DarkRainbow",
 ColorFunctionScaling -> False,
 PlotStyle -> {{Thickness[0.008], AbsoluteDashing[{15, 4, 4, 5}]}}]

enter image description here

$\endgroup$
4
$\begingroup$

Showing how to mess with the internal Graphics structure:

p = Plot[Sin[2 x]^2 Cos[1/2 x]^2, {x, 0, 2 π},  PlotStyle -> {{Thickness[0.008], 
     AbsoluteDashing[{15, 4, 4, 5}]}}]; 
l = Cases[p, Line[a___] :> a, Infinity];
f[x_] := Rescale[x, range, {0, 1}]
range = {Min@#, Max@#} &@l[[1, All, 2]];
p /. Line[___] :>  Line[l[[1]], VertexColors -> 
                                (Blend[{Blue, Yellow}, #] & /@ (f /@ l[[1, All, 2]]))]

Mathematica graphics

$\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.