0
$\begingroup$

How can I have a small size (.EPS) DensityPlot? In fact, I want to bring a lot of density plots in my paper and the teX file will be very heavy. What can I do?

$\endgroup$
7
  • $\begingroup$ DensityPlots are color gradient images. Exporting them into pure vector graphics typically either blows their size up or they look shabby. Maybe exporting a ContourPlot as vector graphic is more feasbile for you... $\endgroup$ May 5, 2018 at 18:44
  • 1
    $\begingroup$ You must be one of the few people who are still using .eps file format for latex. Everyone has moved to PDF for images with latex long time ago. $\endgroup$
    – Nasser
    May 5, 2018 at 19:10
  • $\begingroup$ @ Nasser : Actually, the journal forced the authors $\endgroup$ May 5, 2018 at 19:14
  • $\begingroup$ @ Henrik Schumacher: Would you kindly please guid me more clearly. Tanx $\endgroup$ May 5, 2018 at 19:15
  • 1
    $\begingroup$ @Ak68 (I stumbled upon this just by chance because I was not pinged. There must be no whitespace between the @ and the user name.) If you already have a working Mathematica -> pdf pipeline for export, the simplest way to produce eps files would be to use external tools such as pdf2eps in the command line. Inscape is also an option. Actually, the last time I tried (several years ago, though), I found that the Mathematica eps export was rather buggy. $\endgroup$ May 5, 2018 at 20:34

1 Answer 1

3
$\begingroup$

You probably need to replace the density plot with a Raster. The following makes a 28KB PDF file (sorry, my EPS exporter does not seem to work -- I always use PDF in TeX these days), which approximates DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]. The DensityPlot[..] took 1.8MB.

Legended[
 Graphics[
  Raster[
   Rescale@
    Table[Sin[x] Sin[y], {y, Subdivide[-3., 3., 100]}, {x, Subdivide[-4., 4., 100]}],
   ColorFunction -> "M10DefaultDensityGradient"
   ],
  FrameTicks -> {
    {Charting`ScaledTicks[{1/2 (100 + 33 #) &, -3 + 6 (# - 1/2)/99 &}],
     Charting`ScaledFrameTicks[{1/2 (100 + 33 #) &, -3 + 6 (# - 1/2)/99 &}]},
    {Charting`ScaledTicks[{1/8 (400 + 99 #) &, -4 + 8 (# - 1/2)/99 &}], 
     Charting`ScaledFrameTicks[{1/8 (400 + 99 #) &, -4 + 8 (# - 1/2)/99 &}]}},
  Frame -> True],
 BarLegend[{"M10DefaultDensityGradient", {-1., 1.}}]
 ]

Mathematica graphics

You can adjust the raster size and ImageSize to suit. If they all have the same dimensions and ranges, it might not be a headache. Or one could try to write a general purpose function to do the above. The functions in the ticks just map forward and back between the raster domain {1, 100} and the function domains, {-4., 4.} for x and {-3., 3.} for y.

$\endgroup$
3
  • $\begingroup$ @ Michael E2: No way! The pdf files are too heavy too :( 2 GB!!!!!! On the other hand, above plot do not have a good quality :/ $\endgroup$ May 5, 2018 at 19:56
  • $\begingroup$ @Ak68 You can improve the quality and predict the size, since the size is roughly proportional to n^2 for an n x n raster. But higher quality would seem to imply a larger size. You might be better off with DensityPlot, unless Henrik's suggestion of ContourPlot is acceptable. I have no idea what 2GB has to do with PDF. I don't get anywhere near that size. That's a raster size of ~6000. To get better help, you need to provide an example. $\endgroup$
    – Michael E2
    May 5, 2018 at 20:30
  • 1
    $\begingroup$ @Ak68 That's what I meant. Better export the plot as high resolution png instead as eps. $\endgroup$ May 5, 2018 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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