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?
1 Answer
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.}}]
]
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
.
-
$\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$ 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
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$