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'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:

Mathematica graphic

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

Mathematica graphic

What is going wrong?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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]
share|improve this answer
    
Although it seems a bit "hackish" this was the easiest and worked perfectly. Thanks Mr. Wizard! –  s0rce Jul 31 '12 at 16:42
    
@s0rce glad I could help. :-) –  Mr.Wizard Jul 31 '12 at 16:54
add comment

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]

enter image description here

share|improve this answer
1  
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. –  Szabolcs Jul 26 '12 at 15:22
    
@Szabolcs Yes, true, but this questions has identical plots. –  Vitaliy Kaurov Jul 26 '12 at 17:45
add comment

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]

Mathematica graphics

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.