3
$\begingroup$

I created a simple barlegend:

barlegend = BarLegend[{Hue[#] &, {0, .7}}] 

enter image description here

However, when I tried placing this legend next to any plot, the legend appears differently. It seems that when placed in a plot, my custom range [0, 0.7] is scaled to [0,1] as input for the Hue function. How could I make the legend appear in the same way as it is created? Thank you.

barlegend = BarLegend[{Hue[#] &, {0, .7}}] 

Plot[t + 10, {t, 0, 2}, PlotLegends -> barlegend, 
 Epilog -> Text["Any plot", {.5, 11}]]

enter image description here

$\endgroup$
0

1 Answer 1

4
$\begingroup$

You can use barlegend with Legended

Legended[Plot[t + 10, {t, 0, 2}, Epilog -> Text["Any plot", {.5, 11}]], barlegend]

enter image description here

or add the option ColorFunctionScaling -> False to Plot:

Plot[t + 10, {t, 0, 2}, PlotLegends -> barlegend, 
 ColorFunctionScaling -> False, Epilog -> Text["Any plot", {.5, 11}]]

same picture

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.