1
$\begingroup$

I export 2D and 3D plots to PNG images using the export command. I can set ImageSize->{xsize,ysize} or RasterSize->{xsize,ysize} as an option for export. To me it looks like these commands have the same effect. Is there any practical difference between the two when exporting to PNG?

$\endgroup$
3
  • $\begingroup$ That is because PNG is a raster-based format recognising both raster-friendly ImageSize and RasterSize, whereas SVG is not but a vector-based format. $\endgroup$ Jan 27 at 14:07
  • $\begingroup$ @RitaGeraghty Thanks! Just to be clear. You are saying it doesn't matter? $\endgroup$
    – 220284
    Jan 27 at 16:33
  • $\begingroup$ If you you’re just looking to make sure the plot exports with high resolution, I usually skip both and use ImageResolution -> 300 in my Export command. $\endgroup$
    – MassDefect
    Jan 27 at 17:31
2
$\begingroup$

You may first generate the rasterized image in Mma with specific RasterSize and ImageSize, and then export the alteady generated image as PNG or whatever.

When you do this, the RasterSize controls the image quality, while the ImageSize fixes its geometrical size. For example, let us vary the RasterSize by keeping the ImageSize constant:

 Column@Table[
  Rasterize[
   Plot[Sin[x], {x, 0, 2 \[Pi]}, 
    PlotLabel -> Row[{Style["RasterSize=", 14], Style[sz, 12]}]], 
   ImageSize -> 200, RasterSize -> sz], {sz, {50, 100, 300, 500}}]

enter image description here

Let us now keep the RasterSize constant and vary the ImageSize:

Row@Table[
  Rasterize[
   Plot[Sin[x], {x, 0, 2 \[Pi]}, 
    PlotLabel -> Row[{Style["ImageSize=", 12], Style[sz, 12]}]], 
   ImageSize -> sz, RasterSize -> 200], {sz, {100, 200, 300}}]

enter image description here

One concludes that each size of the image requires its own RasterSize to garantee the image quality.

Have fun!

$\endgroup$
4
  • $\begingroup$ Does this also control the image size in printer points and raster size in pixels for an exported png? $\endgroup$ Jan 27 at 17:32
  • $\begingroup$ Or an exported pdf? $\endgroup$ Jan 27 at 17:38
  • $\begingroup$ Many thanks Alexei, that's very helpful! $\endgroup$
    – 220284
    Jan 27 at 17:49
  • $\begingroup$ @David Keith By definition the option RasterSize determines pixel width and size. $\endgroup$ Jan 27 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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