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]
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]
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:
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}}]
A third possibility is to use GraphicsGrid
with Spacings -> 0
:
GraphicsGrid[{{pl1, pl2}}, Spacings -> 0]
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
?
Answer
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}]
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.
Comments
Post a Comment