0
$\begingroup$

I have a plot with a color-varying line, and am looking to make a color-varying LineLegend to accompany it. However, ColorFunction doesn't work for legends it seems, so I'm not sure how to manage this. For example:

Plot[Sinc[x], {x, 0, 10}, ColorFunction -> Function[{x, y}, ColorData["Rainbow"][y]], PlotLegends -> LineLegend[Automatic, {"Line"}]]

Results in: Result

But I'm looking for the "Line" legend to have a rainbow appearance as well.

$\endgroup$
2
  • $\begingroup$ Plot[Sinc[x], {x, 0, 10}, ColorFunction -> Function[{x, y}, ColorData["Rainbow"][y]], PlotLegends -> BarLegend["Rainbow"]] as a start. $\endgroup$
    – Syed
    Nov 9 '21 at 9:46
  • 2
    $\begingroup$ It is a duplicate of this. $\endgroup$
    – Syed
    Nov 9 '21 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.