2
$\begingroup$

How can I add a BarLegend to the following plot?

b[x_] := x;
p1 = 
  Show[
    Graphics[
      Table[{Hue[i/20], Circle[{0, 0}, b[i]]}, {i, 1, 6, 0.1}], 
      ImageSize -> 350
    ], Frame -> True
  ]
$\endgroup$
12
  • $\begingroup$ Have you already seen Legended[]? $\endgroup$ Jun 22, 2022 at 15:19
  • $\begingroup$ yes. Not working. $\endgroup$
    – AAA
    Jun 22, 2022 at 15:19
  • 2
    $\begingroup$ Well, the hope was that you'd see that Legended[] needs a second argument that is something like BarLegend[{Hue[#/20] &, {1, 6}}], depending on what you are trying to do (which you have not mentioned so far in your question, but should have been there). $\endgroup$ Jun 22, 2022 at 15:23
  • $\begingroup$ Here if you run this code, you will see colored concentric circles dur to Hue. I want to show in the BarLegend that color variation with i. $\endgroup$
    – AAA
    Jun 22, 2022 at 15:27
  • 1
    $\begingroup$ @AkhilUniyal Yeah, it can be done, but it is different enough from this question that it probably warrants asking a new question about it. $\endgroup$
    – MarcoB
    Jun 22, 2022 at 21:07

1 Answer 1

9
$\begingroup$
ClearAll[b]
b[x_] := x

Legended[
 Graphics[
   Table[{Hue[i/20], Circle[{0, 0}, b[i]]}, {i, 1, 6, 0.1}],
   ImageSize -> 350, Frame -> True
 ],
 BarLegend[{Hue[#/20] &, {1, 6}}]
]

concentric circles and legend

$\endgroup$

Your Answer

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

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