I would like to plot a figure with a top to bottom gradient like this:
I drew this figure using Matlab. Is it possible to plot a similar one using Mathematica? I googled some posts, but I do not know how to do this. Is it possible to do it by "filling"? Thank you!
According to Bob's idea, I tried this code:
mx[x_] = -100*x*Exp[-69.3147*x^2]; (*This is my function*) Show[RegionPlot[ mx[x] <= y <= 0 || 0 <= y <= mx[x], {x, -0.5, 0.5}, {y, -5.5, 5.5}, ColorFunction -> "Rainbow", AspectRatio -> 0.75, BoundaryStyle -> None], Plot[mx[x], {x, -0.5, 0.5}], PlotStyle -> Directive[Darker[Blue], Thick]]
Why the right tail is incompleted? If we look the figure carefully, the peak position is also not perfectly match the curve.
According to Michael's and kglr's idea, I tried this code:
mx[t_] = t*Exp[-69.3147*t^2]; (*This is my function*) Get["https://pastebin.com/raw/gN4wGqxe"] JetCM = With[{colorlist = RGBColor @@@ jetColors}, Blend[colorlist, #] &]; ParametricPlot[{t, y*mx[t]}, {t, -0.5, 0.5}, {y, 0, 1}, PlotRange -> All, ColorFunction -> (JetCM[#2 + (25 #2^2 (#2 - 1/2) (1 - #2)^2)/(1 + 100 (#2 - 1/2)^2)] &), AspectRatio -> 0.75, Axes -> False, BoundaryStyle -> {Thick, Black}] /. Line[v_, opts___] :> Line[v[[2 ;; -2]], opts]
Then I got this figure:
The curve is not smooth anymore.
By the way, how to fill an inverse raninbow color? I tried this:
ColorFunction -> ColorData[{"Rainbow", "Reverse"}]
But it does not work.
Plot[Sin[x], {x, 0, 2 Pi}, ColorFunction -> Function[{x, y}, Hue[x]], Filling -> Axis, FillingStyle -> Automatic]
$\endgroup$PlotPoints
to get a smoother curve. $\endgroup$