6
$\begingroup$

According to the documentation

BarLegend is displayed in StandardForm as a graphics object

and it do looks like a normal graphics in front end.

However,

BarLegend["Rainbow"]//FullForm

still gives BarLegend["Rainbow"]

and

Show[BarLegend["Rainbow"]]

will give errors

Show::gtype: BarLegend is not a type of graphics.

So is there a way to convert legends to graphics objects?

$\endgroup$
7
$\begingroup$
First @ Cases[
  ToBoxes @ BarLegend["Rainbow"],
  gr_GraphicsBox :> ToExpression[gr],
  ∞
]
$\endgroup$
  • $\begingroup$ Oh, my god. Any explanations why you are so fast? : ) $\endgroup$ – matheorem May 8 '18 at 13:59
2
$\begingroup$

Also

ToExpression[MakeBoxes[BarLegend["Rainbow"]][[1,1]]][[1]]
$\endgroup$
  • $\begingroup$ It works! Thank you so much! $\endgroup$ – matheorem May 9 '18 at 0:24

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.