I'm trying to create a BarChart on which images are the labels of each bar.

A Minimal example of what I'm trying to do:

image1 = Import["test1.png"];
image2 = Import["test2.png"];
image3 = Import["test3.png"];
BarChart[{0.4, 0.2, 0.8}, ChartLabels -> {image1, image2, image3}]

The problem is the position of the image on the label. The image is not resized to fit within the Bar width, and so it fills a great part of the plot.

Another problem is that the image is not centered: the bottom left corner of it is on the label's expected position, and not the center of it.

Any ideas how I can solve this?


as example of an image, wikipedia's picture of the day:


works for the problem in hands. (Thanks J.M. for pointing out)

  • 1
    $\begingroup$ Where might potential helpers obtain your nice PNGs? $\endgroup$ – J. M.'s technical difficulties Apr 18 '13 at 9:49
  • $\begingroup$ Edited question with an example of importing (jpeg, PNG, is the same for the proposes of the question.) $\endgroup$ – Jorge Leitao Apr 18 '13 at 9:53

I don't know if this is satisfying but you can always manually resize:

BarChart[{0.4, 0.2, 0.8},
 ChartLabels ->
  (Image[#, ImageSize -> 40] & /@
    {image1, image2, image3})

enter image description here

| improve this answer | |
  • $\begingroup$ strangely, the code you presented in my machine/version (Mac OS 10.6, mathematica 9) does not give the result you show. It shows the problem I was trying to solve, namely the image is not centered on the Label's "place holder", but the bottom left corner of it is. $\endgroup$ – Jorge Leitao Apr 18 '13 at 10:06
  • $\begingroup$ @J.C.Leitão this is in version 7 on Windows 7. Sorry, I don't think I'm going to be able to help. :-/ $\endgroup$ – Mr.Wizard Apr 18 '13 at 10:14
  • $\begingroup$ @J.C.Leitão: does BarChart[{0.4, 0.2, 0.8}, ChartLabels -> Placed[(Image[#, ImageSize -> 40] & /@ {image1, image2, image3}), Below]] work? (you can play around with Placed to get other alignments) $\endgroup$ – Pinguin Dirk Apr 18 '13 at 10:46
  • $\begingroup$ @PinguinDirk: I played around, and so far only the answer below works. However, the positions are relative, which really screw the exporting feature. $\endgroup$ – Jorge Leitao Apr 18 '13 at 14:03
  • 1
    $\begingroup$ @J.C.Leitão: well, I see that @cormullion posted just such answer. Below seems fine to me (Mac too) - didn't try to export though. $\endgroup$ – Pinguin Dirk Apr 18 '13 at 15:12

Mr.Wizard's solution doesn't quite work for me on MacOSX/Mathematica9, but a slight tweak of his magic spell works:

BarChart[{0.4, 0.2, 0.8}, 
 ChartLabels -> Placed[{image1, image2, image3}, 
   {{0, 0}, {-0.5, 1}}, 
   (Image[#, ImageSize -> 50] &)]]


| improve this answer | |
  • $\begingroup$ Notice that -0.5 is arbitrary, and needs tweaking depending on the image size. $\endgroup$ – Jorge Leitao Apr 18 '13 at 12:09

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.