How to export Gnuplot output to PNG, JPG and PDF

Last updated on August 21, 2020 by Dan Nanni

Gnuplot allows you to export its output to different formats. To export Gnuplot output, you just specify a terminal which then, depending on the type of the terminal, determines the format of output file. Gnuplot supports terminals for various formats including PNG, JPG, GIF and PostScript. In order to export Gnuplot output to one of these formats, you simply specify a corresponding terminal in Gnuplot.

To export Gnuplot output to PNG format:

set terminal png size 400,300 enhanced font "Helvetica,20"
set output 'output.png'

To save Gnuplot output as JPG format:

set terminal jpg color enhanced "Helvetica" 20
set output "output.jpg"

To convert Gnuplot output to GIF format:

set terminal gif color enhanced
set output "output.gif"

If you would like to save Gnuplot output as any other formats than those supported by native Gnuplot terminals, you can use redirect operator |, to redirect Gnuplot's native output to an external tool for format conversion.

For example, to export Gnuplot output to PDF format, first install ps2pdf which is contained in Ghostscript package. Then redirect Gnuplot's poscript output to PDF format.

$ sudo apt-get install ghostscript
set terminal postscript
set output '| ps2pdf - output.pdf'

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean