Hybrid bitmap/vector plots with gnuplot

Hybrid bitmap/vector plots with gnuplot

 

http://www.adamcrume.com/blog/archive/2013/03/12/hybrid-bitmapvector-plots-with-gnuplot

 

 

I have a LaTeX document that includes a plot of a large dataset generated with gnuplot.  Everything’s fine, except that the resulting PDF is huge because of the enormous number of points in the plot.  A quick fix for this would be to switch the gnuplot terminal from epslatex to png.  Unfortunately, that also affects the text in the plot, which no longer matches the text in the document.  What is really needed is a pnglatex terminal.  Since that doesn’t exist, I hacked it.

The idea is to take advantage of the fact that the epslatex terminal already splits the text from the graphics.  First, we convert the .eps file to a .png with ImageMagick:

convert -density 288 myplot.eps myplot.png

The density argument is the DPI at which to generate the PNG.  This may need to be tweaked to minimize pixelation and aliasing artifacts.  Depending on your PDF viewer, higher may not necessarily be better.  Next, we change the generated .tex file to include our .png instead of the .eps:

sed -r 's:\\includegraphics\{([^}]+)\}:\\includegraphics[scale=0.25]{\1.png}:g' 
< myplot.tex > myplot-png.tex

The default DPI seems to be 72, so the scale argument should be 72 divided by the density argument to ImageMagick.  Finally, include myplot-png.tex instead of myplot.tex in the main document.

Note that rasterization necessarily loses information, and the result is of lower quality than using the epslatex terminal.  The resulting PDF can be much smaller, though, so the tradeoff may be worth it.

你可能感兴趣的:(bitmap)