# Exporting a rasterized Row of Graphics

I'm running some code based on @R.M.'s answer to this question to create a couple plots side by side.

I want to export the plots rasterized to a png. However, when I Rasterize the plot at a higher RasterSize or ImageResolution it splits the row on to two seperate lines. See the following simplified example below:

Rasterize[
With[{size = 250},
Row[Show[#, ImageSize -> {Automatic, size},
ImagePadding -> {{30, 15}, {40, 5}}] & /@ {Plot[
Sin[x], {x, -1, 1}], Plot[Sin[x], {x, -1, 1}]}]],
ImageResolution -> 200]


It looks like this:

I want both plots on the same line but at higher resolution, like this:

What is going wrong?

It is possible to give an explicit ImageSize to Row and if it is large enough to contain the graphics it will not wrap. If it is given in the form {maximum} it will be sized automatically. Infinity does not appear to work so I used 1*^6:

Rasterize[
With[{size = 250},
Row[Show[#, ImageSize -> {Automatic, size},
ImagePadding -> {{30, 15}, {40, 5}}] & /@ {Plot[
Sin[x], {x, -1, 1}], Plot[Sin[x], {x, -1, 1}]},
ImageSize -> {1*^6}]],
ImageResolution -> 200]

• Although it seems a bit "hackish" this was the easiest and worked perfectly. Thanks Mr. Wizard! Commented Jul 31, 2012 at 16:42
• @s0rce glad I could help. :-) Commented Jul 31, 2012 at 16:54
• @Mr.Wizard Thank you. Mathematica will create wrapped EPS files when not rasterized, even if right-clicking the Row-created graphics cell bracket and using "Save as...". Your solution works even without the Rasterize command. Commented Oct 24, 2018 at 19:08

You can change from Row over to Grid, which does no linebreaking. Then you just need to add another set of curly braces around your former input row:

Rasterize[
With[{size = 250},
Grid[{Show[#, ImageSize -> {Automatic, size},
ImagePadding -> {{30, 15}, {40, 5}}] & /@ {Plot[
Sin[x], {x, -1, 1}], Plot[Sin[x], {x, -1, 1}]}}]],
ImageResolution -> 200]


• This is the simplest solution IMHO, and works in Mathematica 12. Commented Aug 28, 2019 at 4:45

Use GraphicsRow to avoid breaking the row. You can control the resolution of your exported image with the option ImageSize -> ... supplied directly to GraphicsRow. This is another advantage of GraphicsRow over Raw - it takes ImageSize option. Yet with most of other objects using plane Row is more preferable.

And though I did not use Rasterize, and exported directly, you can still use it if you want to.

Export["test.png", With[{size = 250},
GraphicsRow[Show[#, ImageSize->{Automatic, size},ImagePadding->{{30, 15}, {40, 5}}] & /@
{Plot[Sin[x], {x, -1, 1}], Plot[Sin[x], {x, -1, 1}]},Spacings-> 0]], ImageSize -> 500]


• GraphicsRow has it's own problems: the two cells will be the same width even if the graphics are not. This is what motivated my question that s0rce is linking to. Commented Jul 26, 2012 at 15:22
• @Szabolcs Yes, true, but this questions has identical plots. Commented Jul 26, 2012 at 17:45