Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I needed to overlay a small histogram onto a large image, specifically in the bottom right hand corner. However, I could not do this in an intuitive and computationally cheap fashion due to inexperience. There are two images, the histogram

imgHist=Histogram[{filtGreenLengths, filtRedLengths}, 20, Background -> White,
  ImageSize -> {200, 100}]

and the main image


I first tried to directly perform the overlay, using the code

finalPic = ImageCompose[image, {imgHist,0.5}, Scaled[{0.9, 0.085}]]

but the ImageCompose function freaked out and stretched imgHist to equal the size of image and then moved the enormous expanded imgHist to the bottom right hand corner. I could not find an option to turn off this auto-stretching in the documentation. In the end, I had to do this

imgHist = 
   Histogram[{filtGreenLengths, filtRedLengths}, 20, 
    Background -> White, 
    ImageSize -> {200, 100}], {ImageDimensions[image][[1]], 
    ImageDimensions[image][[2]]}, Padding -> Transparent];

in order to get the result I wanted. This appears to be pretty silly and redundant, so what would be a less hackish way of doing this?

share|improve this question
up vote 5 down vote accepted

Does something like this go in the right direction?

enter image description here

share|improve this answer

You could try using an epilog with inset though I'm not sure how much more efficient that'd be compared to the method you have.

TestData = {10, 14, 8, 6, 4, 3, 2.5, 2, 1.5, 1};
TestDataSmall = {2.5, 1.8, 1.5, 1.3, 1.2, 1.};
plotSmall = Histogram[TestDataSmall, PlotRange -> {0, 6}, ImageSize -> {400, 150}];
Histogram[TestData, PlotRange -> {0, 16}, 
    Epilog -> Inset[plotSmal], 
                    Scaled[{0.75, 0.75}]] ]
share|improve this answer

You should have typed in documentation center that what you are looking for: "overlay" :) Usualy when I'm looking for anything it gives me something.

Also, I always scan See also links (there is Inset in ImageCompose page)

pic = Image[Import["ExampleData/lena.tif"], ImageSize -> 400]
hist = ImageHistogram[pic, ImageSize -> {150, 50}, Background -> Black]

        }, All, 2, Alignment -> {1, -1}]

enter image description here

share|improve this answer

Your Answer


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.