Yesterday, I was doing any Tables of 15 graphs similar to the next example, to save .eps and use in latex.

In the generation of the graphs Mathematica spends many time. Is possible to reduce this time, and work for the cpu?

I found that Mathematica save .eps with a big (not necessary) size. between 4 and 5 MB. When it´s obvious that for this image 400 or 500 KB is enough.

So... how to obtain eps from MAthematica with a reasonable size (10-20% of the size that I have commented)

In this example

ContourPlot[peaks[x, y], {x, -2, 2}, {y, -2, 3}, 
 ColorFunction -> "DarkRainbow", ContourLines -> False, 
 Contours -> 25, LabelStyle -> {Bold, 20}, 
 Epilog -> {Black, PointSize -> .036, Point[ {{1, 2}, {1.5, 2.5}}], 
   Cyan, PointSize -> .036, Point[ {{-1, 2}, {-1.5, 2.5}}]}, 
 ImageSize -> 300]

Yesterday I resolve the problem, saving jpg/png and converting to .eps to can use in latex, because I put 12 or 15 images per page, and don´t need a high quality, but I would like any solutions to this issue.

  • 1
    $\begingroup$ I'd just do as you did. save to png and then use convert to eps (level 3, to get best compression). I do not know of option in M do that. I myself save to png then convert outside. $\endgroup$ – Nasser Jun 16 '14 at 7:41
  • 1
    $\begingroup$ you could use export[fname_, im_,opts___] := Export[fname, Rasterize[im,ImageResolution->300],opts] $\endgroup$ – chris Jun 16 '14 at 7:41
  • $\begingroup$ Once again I ask you to take the time to format your code properly. And that includes not dumping it into the editor as one long line that requires readers to do a lot of scrolling, $\endgroup$ – m_goldberg Jun 16 '14 at 7:44
  • 1
    $\begingroup$ @Pickett Yes, precisely the Ian Thompson´s comment has induce me to start this issue in the MathematicaSE $\endgroup$ – Mika Ike Jun 16 '14 at 7:53
  • 1
    $\begingroup$ fyi, the convert command using level3 eps is this convert file.png eps3:file.eps notice no space between eps3: and file.eps $\endgroup$ – Nasser Jun 16 '14 at 18:19

Try to use the FixPolygons package by Will Robertson. It merges adjacent polygons with the same color producing vector image of lesser size with the same (or ever better) quality.

For installing the package you should copy the FixPolygons.m file to the "Mathematica/Applications" directory in your user profile. Then you can use it as follows:

<< FixPolygons`
g2 = g // FixPolygons
Export["test.eps", g2]

In the case the above does not fit your needs but you wish to produce high-quality output you can try to use the "rasters in vectors" approach described here (originally proposed here) for 3D graphics (but the same method will work for 2D graphics). The idea it to rasterize only the largest and problematic part of the vector image - the contour plot itself, keeping axes and labels in vector form. This will dramatically reduce the size of the exported EPS file while allowing you to get any resolution you need.

You can also try Jens Nöckel's "rasters in vectors" functions published on his homepage (see also his answer here).

  • $\begingroup$ @alexy-popkov I have tested your propose, but the result is equela 4.5 MB for that image. $\endgroup$ – Mika Ike Jun 16 '14 at 8:07
  • $\begingroup$ @Mika I have added description of another approach. $\endgroup$ – Alexey Popkov Jun 16 '14 at 8:20
  • $\begingroup$ Yes, I refer to the initial ( FixPolygons ) proposal. The other link I´ll try later, still not be tested. Thank you. $\endgroup$ – Mika Ike Jun 16 '14 at 8:28

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.