How to reduce the EPS-format output of gnuplot?
My solution for this problem is the "every" command in gnuplot, i.e.
plot "datafile" u 1:2 every 10
Like this you can already reduce the size of the eps graphics by ~ a factor of 10. of course you need to find out yourself how much data you can omit without loosing too much information, i.e. the figure should still contain all the features you want to visualize.
If this is not wanted, I normally convert the eps to a raster image of appropriate size and convert it back to eps. Also here you have to play around with the resolution etc
The problem with .eps files is not necessarily resolution (they are vector graphics), but the amount of information gnuplot includes when creating the file. Gnuplot has a tendency to draw .eps files with lots of extra information, especially for 2D plots and plots with lots of points. For instance, for a grid of red squares joined at the edges to make a big red square, gnuplot would draw tons of little red squares instead of the big square. This issue is mentioned at the end of this blog post, where they say that plot ... with image
creates a much smaller output than splot
for making heat maps.
It sounds like you are not using splot
, though, so you could try making a .pdf instead of .eps, and if you need .eps convert it using pdf2ps
or another program. That might help...
Out of curiosity, how many points are you plotting? If you could give an idea of the amount of data you use, along with some example code you are using right now, we might be able to give better ideas.
I encountered a similar problem where a scatter plot of more than 10^6 points resulted in PDF files of >100 MB. The points were drawn with a very low opacity (1%) so only many layered points would be visible at all, resulting in something more of a smooth density distribution rather than a scatter plot. Thus, I was very reluctant to follow Raphael Roth's advise and thin out the data.
Instead, I found it useful to create a separate Gnuplot script to plot the data using the pngcairo
terminal to PNG bitmap images of sufficient resolution. This plot has no axes, not tics, no border and no margins -- just the data drawn in the appropriate coordinates:
set terminal pngcairo transparent size 400,400
set output 'foo.png'
set margins 0,0,0,0
set border 0
unset xtics
unset ytics
# set xrange, yrange appropriately
plot ... with points notitle
Then, in the actual plot (for which I used the cairolatex
terminal), I plot this PNG image:
set terminal cairolatex pdf
# regular setup, using the same xrange and yrange
plot 'foo.png' binary filetype=png with rgbalpha axes x2y2
Note that I plot using the other (ticless) set of axes to ensure that the image is filling the graph area without any border, so the tics on the x1y1 axes match the actual position of the points the scatter plot.
The PNG ended up being only a few dozen kilobytes, the PDF was a couple of MB. I think the rgbalpha
plot style (similar to with image
) is not the most efficient but this was good enough for me.
Hope someone will find this useful.