6
$\begingroup$

I need to produce the legend of a plot which encodes a color gradient together with a color gradient. In particular, I would like the image bellow to have the blueish edge faded and the redish solid:

enter image description here

I thought Graphics would be a good way to implement it, but I couldn't figure out how to implement such varying opacity. This would be the legend of the following plot

enter image description here

as you can see, the points at the plot display such gradient, but the way I implemented it was assigning an opacity to each point at the listplot, and this does not seem to work either for Graphics or for the above shown Bar Legend.

$\endgroup$
7
$\begingroup$

"to have the blueish edge faded and the redish solid::

You can use a list of colors with desired opacities as option value for "ColorScheme". For example,

colorscheme = Append[ColorData["DarkRainbow"]@#, .01 + #] & /@ Subdivide[10];

Graphics[ChartElementData["GradientRectangle", 
   "ColorScheme" -> colorscheme,  "GradientOrigin" -> Left][{{0, 15}, {0, 2}}]]

enter image description here

$\endgroup$
0
5
$\begingroup$

One can also have a legend which shows colour and opacity separately, as

BarLegend["Rainbow", OpacityFunction -> (# &)]

enter image description here

This is used in built-in functions such as DensityPlot3D.

$\endgroup$
0

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.