How to reduce gnuplot output in EPS format?

I have a large amount of data from which I would like to create a scatter plot and include it in a LaTeX document. I use gnuplot to generate a scatter plot with the epslatex output format to easily import data into a LaTeX document.

My problem is that the EPS files are too large (approximately 14 MB per shape), which will result in a very large output document. Obviously, the reason is that all the data is included in the EPS file, which is not needed.

However, I could not find a way to compress the EPS file. The only way is to reduce the number of samples that I have, but for technical reasons, I would prefer not to.

Can someone suggest me a way to reduce the size of EPS graphics?

I tried using ImageMagick and decreasing the resolution of the EPS files (e.g. convert -units PixelsPerInch plot.eps -density 300 plot2.eps ), but it reduces the sizes, which is not what I want.

Thanks in advance,

+5
source share
3 answers

My solution for this problem is "every" command in gnuplot, i.e.

 plot "datafile" u 1:2 every 10 

Thus, you can already reduce the size of graphics in the EPS format by about 10 times. Of course, you need to find out how much data you can omit without losing too much information, that is, the figure should contain all the functions that you want to visualize.

If this is not required, I usually convert eps to a bitmap of the appropriate size and convert it back to EPS. Also here you have to play with permission, etc.

+4
source

The problem with .eps files is not necessarily a resolution (they are vector graphics), but the amount of information gnuplot includes when creating the file. Gnuplot tends to draw .eps files with a lot of additional information, especially for 2D graphics and areas with a lot of points. For example, for a grid of red squares connected at the edges to make a large red square, gnuplot would draw tons of small red squares instead of a large square. This issue is mentioned at the end of this blog post , which says that plot ... with image produces a much smaller result than splot to create map heat.

It looks like you are not using splot , although you can try making .pdf instead of .eps, and if you need .eps, convert it using pdf2ps or another program. This can help...

Out of curiosity, how many points do you plot? If you could give an idea of ​​the amount of data that you are using, along with some sample code that you are using right now, we could give better ideas.

+2
source

I encountered a similar problem when a spread of more than 10 ^ 6 points resulted in PDF files> 100 MB in size. The points were drawn with very low opacity (1%), so that only a lot of layered points would be visible, which would lead to something smoother distribution of density than to the scatter plot. Thus, I was very reluctant to follow the advice of Raphael Roth and thin out the data.

Instead, I found it useful to create a separate Gnuplot script for pngcairo data from the pngcairo terminal pngcairo for PNG raster images with sufficient resolution. There are no axes, ticks, borders and fields on this chart - only data displayed in the corresponding 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, on the actual chart (for which I used the cairolatex terminal), I cairolatex 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 am plotting using a different set of axes (without a tick) to ensure that the image fills the plot region without any border, so the labels on the x1y1 axes correspond to the actual position of the points in the scatter plot.

PNG size was only a few tens of kilobytes, PDF - a couple of MB. I think rgbalpha plot (similar to with image ) is not the most effective, but that was enough for me.

Hope someone finds this helpful.

0
source

Source: https://habr.com/ru/post/1488150/


All Articles