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.

This question already has an answer here:

Suppose that I have two plots, pl1 and pl2:

pl1 = Plot[x, {x, 0, 1}, Frame -> True, ImageSize -> 350]
pl2 = Plot[x^2, {x, 0, 1}, Frame -> True, ImageSize -> 350]

pl1

pl2

I would like to (1) combine these plots side-by-side in a (2) non-rasterized graphic with (3) no spacing.

I get pretty close to my desired result by using Grid with Spacings -> 0:

Grid[{{pl1, pl2}}, Spacings -> 0]

grid

The above satisfies my requirements (2) and (3): the result is non-rasterized, and there is no spacing between the plots. However, the above doesn't satisfy my requirement (1), that the plots be combined into a single Graphic object. That is, if I click on either of the plots, I see that they are separate Graphic objects:

gridA

gridB

So the above approach doesn't satisfy all of my requirements. (Why do I need the plots to be combined in a single Graphic? The reason is that I want to be able to place other Graphic objects -- e.g., text, arrows, shapes, etc. -- that span the two plots.)

Another possibility is to use ImageAssemble, but unfortunately this leads to a rasterized image:

ImageAssemble[{{pl1, pl2}}]

imageassemble

A third possibility is to use GraphicsGrid with Spacings -> 0:

GraphicsGrid[{{pl1, pl2}}, Spacings -> 0]

graphicsgrid

It seems that this produces a single Graphic object ((1)) that is not rasterized ((2)), but, unfortunately, there is spacing between the plots.

Do you have any suggestions? Is there any way to remove the spacing/padding in GraphicsGrid?

share|improve this question

marked as duplicate by Jens, Michael E2, m_goldberg, belisarius, Pickett Mar 12 at 21:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
@Jens Thanks. I think my question is more general, though. I just want to combine two Graphics objects side-by-side. It's almost like I am looking for a way to flatten a Grid objects so that two Graphics objects in neighboring cells are combined into a single Graphics object. –  Andrew Mar 11 at 21:11
1  
Why do you need the result to be a single Graphics object? What properties do single Graphics objects have that you need to rely on later? This is a very important question. You can combine them using Insets, but I'm not sure you'll like the result, as it might not behave the way you expect when you resize it. –  Szabolcs Mar 11 at 22:15
    
Nowadays I use SciDraw for figures with multiple panels: mathematica.stackexchange.com/a/37880/12 But again, you can't resize a SciDraw figure directly. You have to decide on the size when you make it. –  Szabolcs Mar 11 at 22:16

1 Answer 1

You could do something like the following:

pl1=Plot[x,{x,0,1},Frame->True,ImageSize->350, 
 ImagePadding->{{Scaled[0.05],None},{Automatic,Automatic}}];
pl2=Plot[x^2,{x,0,1},Frame->True,ImageSize->350, 
 ImagePadding-> {{None,Scaled[0.05]},{Automatic,Automatic}}];

GraphicsGrid[{{pl1,pl2}},Spacings->{Scaled[-0.07],0}]

enter image description here

This removes the padding from the graphics themselves with the option ImagePadding, and a magic number of -0.07...There is likely a better way.

share|improve this answer
    
Unfortunately, in this answer, the result is not a single Graphic object. Sorry. –  Andrew Mar 11 at 20:32
    
Yikes you are right... –  chuy Mar 11 at 20:36
    
changed to make result a Graphics –  chuy Mar 11 at 21:06

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