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$ 2 days ago
  • $\begingroup$ yes. Not working. $\endgroup$
    – AKU
    2 days ago
  • 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$ 2 days ago
  • $\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$
    – AKU
    2 days ago
  • 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
    2 days ago

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, privacy policy and cookie policy

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