Mathematica Asked by Harold on February 3, 2021
I’m trying to use an image as a ChartLabel
and I’m getting strange results.
Here is a bar chart, with labels, that looks ok:
But when I try to replace the “A” label with an image, the output is confusing:
Specifically, the image overlaps the plot and is scaled weirdly.
I’d like it to be small, and centered, as the “A” label is in the image above.
What’s the right way to use an image as a ChartLabel
?
How about using ChartElements
instead of ChartLabels
.
images = ExampleData[{"TestImage", #}] & /@ {"Lena", "Mandrill"};
BarChart[{{1, 2, 3}, {4, 5, 6}}, ChartElements -> {images, None}]
Answered by MinHsuan Peng on February 3, 2021
Update: The option LabelingSize
provides a convenient way to size the images.
images = ExampleData[{"TestImage", #}] & /@ {"Lena", "Elaine", "Mandrill"};
is = 60;
bs = .2;
BarChart[Thread[Labeled[{1, 2, 3}, images, Below]],
BarSpacing -> bs, LabelingSize -> is (1 - bs), ImageSize -> 1 -> is]
With is = 120
and bs = .3
we get:
Original answer:
images = ExampleData[{"TestImage", #}] & /@ {"Lena", "Elaine", "Mandrill"};
BarChart[{1, 2, 3}, ChartLabels ->
Placed[Thumbnail[#, Tiny] & /@ images, Axis, Panel[#, FrameMargins -> 0] &]]
Alternatively, you could use Magnify
instead of Thumbnail
:
BarChart[{1, 2, 3},
ChartLabels -> Placed[images, Axis, Framed[Magnify[#, .3], FrameStyle -> None] &]]
Few more alternatives that produce similar pictures:
BarChart[{1, 2, 3}, ChartLabels -> (Framed[Magnify[#, .3], FrameStyle->None] & /@ images)]
BarChart[{1, 2, 3}, ChartLabels -> Placed[Pane[Magnify[#, .1]] & /@ images, Axis]]
BarChart[{1, 2, 3}, ChartLabels->Placed[Framed[Magnify[#, .3],
FrameStyle -> None]& /@ images, Axis]]
Answered by kglr on February 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP