Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

EDIT:

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

image1=image2=image3=Import["http://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Cabiria_1914_poster_restored.jpg/401px-Cabiria_1914_poster_restored.jpg"]

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

share|improve this question
1  
Where might potential helpers obtain your nice PNGs? –  J. M. Apr 18 '13 at 9:49
    
Edited question with an example of importing (jpeg, PNG, is the same for the proposes of the question.) –  J. C. Leitão Apr 18 '13 at 9:53

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
    
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. –  J. C. Leitão Apr 18 '13 at 10:06
    
@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. :-/ –  Mr.Wizard Apr 18 '13 at 10:14
    
@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) –  Pinguin Dirk Apr 18 '13 at 10:46
    
@PinguinDirk: I played around, and so far only the answer below works. However, the positions are relative, which really screw the exporting feature. –  J. C. Leitão Apr 18 '13 at 14:03
1  
@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. –  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] &)]]

chart

share|improve this answer
    
Notice that -0.5 is arbitrary, and needs tweaking depending on the image size. –  J. C. Leitão Apr 18 '13 at 12:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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