How to export Gnuplot output to png, jpg and pdf

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'

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

3 thoughts on “How to export Gnuplot output to png, jpg and pdf

  1. Perhaps it's a version difference, but my gnuplot doesn't recognize "jpg" as a driver, but instead wants "jpeg". It also doesn't accept "color" as an input parameter, and it doesn't like fonts specified as you show. So it wants

    set terminal jpeg enhanced font helvetica 20

    instead of

    set terminal jpg color enhanced "Helvetica" 20

    Thanks for pointing me in the right direction, though.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *