Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:17:11+00:00 2026-05-26T13:17:11+00:00

How to optimize size of an eps or pdf file generated by Mathematica? It

  • 0

How to optimize size of an eps or pdf file generated by Mathematica?

It is common that the file size is 50-100x bigger that it should be (an example below). For some applications (e.g. putting a figure in a publication, or even more – putting it on a large poster) I need to have axes in vector graphics, so using raster graphics for everything is not the best option for me.

Every practical solution (either with setting the right options in Mathematica or with doing further conversions in other applications) will be appreciated.

For example the following code producing an eps figure of:

plot = ListDensityPlot[
Table[Random[], {100}, {100}],
InterpolationOrder -> 0]

Export["testplot.eps", plot]
Export["testplot.pdf", plot]

produces an eps file of size of 3.3MB and a pdf size of 5MB (on Mathematica 7 on Mac OS X 10.6, if it makes a difference).

For a comparison, a 3×3 plot with the same axes has 8kB (pdf) to 20kB (eps).
100×100 points is 30kB in bmp (and a bit less in png).

The issue is the same for other types of plots, with the emphasis on ListPlot3D.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:17:12+00:00Added an answer on May 26, 2026 at 1:17 pm

    You may have figured out how to apply Alexey’s answer in the link he provided. But in case you are having trouble here I provide how I apply the technique to 2D graphics.

    I have found the hard way that if you want to create a good plot you need to be very specific to Mathematica. For this reason, as you may have noticed in my post Rasters in 3D I created an object specifying all the options so that Mathematica can be happy.

    in = 72;
    G2D = Graphics[{},
       AlignmentPoint -> Center, 
       AspectRatio -> 1,
       Axes -> False,
       AxesLabel -> None,
       BaseStyle -> {FontFamily -> "Arial", FontSize -> 12},
       Frame -> True,
       FrameStyle -> Directive[Black],
       FrameTicksStyle -> Directive[10, Black],
       ImagePadding -> {{20, 5}, {15, 5}},
       ImageSize -> 5 in, 
       LabelStyle -> Directive[Black],
       PlotRange -> All,
       PlotRangeClipping -> False,
       PlotRangePadding -> Scaled[0.02]
    ]; 
    

    I should mention here that you must specify ImagePadding. If you set it to all your eps file will be different from what Mathematica shows you. In any case, I think having this object allows you to change properties much easily.

    Now we can move on to your problem:

    plot = ListDensityPlot[
      Table[Random[], {100}, {100}],
      InterpolationOrder -> 0,
      Options[G2D]
    ]
    

    Output

    The following separates the axes and the raster and combines them into result:

    axes = Graphics[{}, AbsoluteOptions[plot]];
    fig = Show[plot, FrameStyle -> Directive[Opacity[0]]];
    fig = Magnify[fig, 5];
    fig = Rasterize[fig, Background -> None];
    axes = First@ImportString[ExportString[axes, "PDF"], "PDF"];
    result = Show[axes, Epilog -> Inset[fig, {0, 0}, {0, 0}, ImageDimensions[axes]]]
    

    Output2

    The only difference here, which at this point I cannot explain is the axes labels, they have the decimal point. Finally, we export them:

    Export["Result.pdf", result];
    Export["Result.eps", result];
    

    The result are files of sizes 115 Kb for the pdf file and 168 Kb for the eps file.

    UPDATE:

    If you are using Mathematica 7 the eps file will not come up correctly. All you will see is your main figure with black on the sides. This is a bug in version 7. This however is fixed in Mathematica 8.

    I had mentioned previously that I did not know why the axes label were different. Alexey Popkov came up with a fix for that. To create axes, fig and result use the following:

    axes = Graphics[{}, FilterRules[AbsoluteOptions[plot], Except[FrameTicks]]];
    fig = Show[plot, FrameStyle -> Directive[Opacity[0]]];
    fig = Magnify[fig, 5];
    fig = Rasterize[fig, Background -> None];
    axes = First@ImportString[ExportString[axes, "PDF"], "PDF"];
    result = Show[axes, Epilog -> Inset[fig, {0, 0}, {0, 0}, ImageDimensions[axes]]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following example should I expect that values.size() will be called every time
I'm trying to optimize the size of my Delphi classes so that they take
How do you optimize the heap size usage of an application that has a
It seems that -O2 is always generated unless I specify optimize-speed (which results in
I am using GraphicsMagick to reduce the file size of PNG images. Some PNG
I have a Django query and some Python code that I'm trying to optimize
I am trying to optimize my TCP/IP settings such as TCP Window size, MSS
I am trying to optimize some stored procedures on a SQL Server 2000 database
Does the compiler optimize out any multiplications by 1? That is, consider: int a
I need to optimize code to get room for some new code. I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.