How can we apply a color gradient (say "Rainbow") to a Rectangle primitive ? Of course, I searched the documentation :
http://reference.wolfram.com/language/ref/Rectangle.html,
and also the site :
How to colorize a rectangle with a given color function? https://stackoverflow.com/questions/8142179/gradient-fill-using-graphics-in-mathematica
but didn't found something clear about the Rectangle primitive. I have the impression that this graphics primitive cannot have a color gradient applied to it.
Here's a MWE code to work with (the Red color in the Rectangle primitive should be remplaced with an horizontal 50% translucent "rainbow" gradient) :
SpectreVisible = Graphics[{Red, Rectangle[{380, -1}, {700, 8}]}];
Manipulate[
Show[
SpectreVisible,
PlotRange -> {{0, 1000}, {0, 7}},
AspectRatio -> 1,
Frame -> True,
GridLines -> Automatic,
GridLinesStyle -> Directive[Gray, Dashed],
Ticks -> Automatic,
ImageSize -> {600, 600}
],
FrameMargins -> None
]
The Manipulate code isn't essential here, but that rectangle would be used inside a Manipulate box.
EDIT : The possible duplicates aren't helping much. The codes are very complicated there, and doesn't address the issue with a simple Rectangle primitive.




Raster[]instead. – J. M.'s missing motivation Mar 16 '16 at 01:45