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 have two plots, both with the exact same formatting (frame, text style, etc.). One of them has 2-digit values for the y axes, the other has scientific notation because the value are large. In addition, they can have a different number of lines for the Axes labels.

I set ImageSize->250, and the bounding boxes of the images (plots) are set to 250 pixels. Cool. Normally this is fine. However, when the two plots have different axes or labels, this results in:

ImageSize->250. Bounding boxes of images are the same

What I want is the actual plot area to be the same, without manually adjusting ImageSize for the 2nd image:

The Plot areas are the same size, but the bounding box for the entire image is different.

Notice how the labels make the bounding box grow outward, but the plot area size is the same (also in width, just not shown). In this particular example, the right image has ImageSize->280.

Does anyone know how to set the plot area size rather than the ImageSize?

EDIT 1:

@anononononomous mentioned a function to get the max padding size, and then apply it to each plot. This is getting closer! But it's clipping the FrameLabel:

(Also, sorry for adding more data, it doesn't change the question though).

anononononomous's solution

share|improve this question
    
I believe GraphicsGrid will equalize the heights. –  David Carraher Dec 14 '12 at 20:10
    
I think, if you use the same values for the options ImageSize and ImagePadding in both plots, you should get the same plot area size in both. –  kguler Dec 14 '12 at 20:44
    
@NasserM.Abbasi Correct, DavidCarraher's solution is not sufficient. kguler, That's getting closer. If you pad the images enough, then you can get the plot area sizes eqaul. However, you end up with a lot of extra space between images (if they're in a list, for example). –  dthor Dec 14 '12 at 20:55
add comment

2 Answers 2

up vote 4 down vote accepted

With fingers crossed that someone will come up with a less manual method, I suggest the following completely manual approach: use the same setting for ImageSize and ImagePadding in all the plots to get the plot area sizes equalized.

 bwc1 = BoxWhiskerChart[data, FrameTicks -> Automatic, 
  LabelStyle -> Green, FrameLabel -> {{Style["y axis", Bold, 14, Green], None}, 
  {Style["x axis", Bold, 14, Green], None}},
  ImageSize -> 300, ImagePadding -> {{85, 5}, {50, 5}}];
 bwc2 = BoxWhiskerChart[100 data, 
   PlotLabel -> Style["line 1\nline 2", Bold],
   FrameTicks -> Automatic, LabelStyle -> Directive[Bold, Blue],
   FrameLabel -> {{Style["y axis", Bold, 14], None}, 
    {Style["y axis", Bold, 14], None}},
   ImageSize -> 300, ImagePadding -> {{85, 5}, {50, 5}}];
 bwc3 = BoxWhiskerChart[100000 data, 
   PlotLabel -> Style["line 1\nline 2\nline 3", Bold, 24],
   FrameTicks -> Automatic, LabelStyle -> Directive[Bold, 16, Red],
   FrameLabel -> {{Style["y axis", Bold, 14], None}, 
      {Style["y axis", Bold, 14], None}},
  ImageSize -> 300, ImagePadding -> {{85, 5}, {50, 5}}];

you get the same plot area size for all three plots:

 Overlay[{bwc1, bwc2, bwc3}, Alignment -> {Right, Bottom}]

enter image description here

But ... "you end up with a lot of extra space between images":

 Grid[{{bwc1, bwc2, bwc3}}, Alignment -> Bottom]

enter image description here

If you wrap each plot in Framed and set the FrameMargins for each to get rid of the extra spaces on the left:

 fbwc1 = Framed[bwc1, FrameStyle -> None, FrameMargins -> {{-50, 0}, {0, 0}}];
 fbwc2 = Framed[bwc2, FrameStyle -> None, FrameMargins -> {{-40, 0}, {0, 0}}];
 fbwc3 = Framed[bwc3, FrameStyle -> None, FrameMargins -> {{0, 0}, {0, 0}}];

you get equal plot area sizes:

 Overlay[{fbwc1, fbwc2, fbwc3}, Alignment -> {Right, Bottom}]

enter image description here

and no extra spaces on the left:

 Grid[{{fbwc1, fbwc2, fbwc3}}, Alignment -> Bottom]

enter image description here

share|improve this answer
    
+1 nice use of negative frame margins –  Mike Honeychurch Dec 14 '12 at 22:08
    
I'm not sure how you could automate this. It looks like a manual method to me ...but if someone is doing a lot of these they can presumably set up a template once and then use repeatedly. –  Mike Honeychurch Dec 14 '12 at 22:09
add comment

As stated above you need to have the ImagePadding set the same for every image, you want to use the getMaxPadding function used in this post: Programmatically combine 2D contour plots with 1D projections

share|improve this answer
add comment

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.