Cheat Logo

Cheat Sheet

Making graphs look good

Level: Intermediate
OS:
  • OS X
  • Linux
  • BSD
  • Solaris
Programs:
  • Gnuplot

If you intend to display a graph on a webpage, the best format to use is PNG. Unfortunately, the gnuplot PNG terminal doesn't always produce the best looking graphs. You can often get better results by plotting with dimensions double the final size you want, then resampling the image. For example, if you want to make a graph 300x300 pixels with 9 point labels, plot at 600x600 with the font size set to 18. Then resize the image. An easy way to do this is with ImageMagick. My plot commands will look something like this:

set terminal png enhanced \
   font "/Library/Fonts/Verdana.ttf" 18  \
   size 2*300, 2*300
set output "plot.png"
set title "Title Text" -2,0 font "/Library/Fonts/Verdana.ttf,22"
set ylabel "Y label" 1.2,0  font "/Library/Fonts/Verdana.ttf,20"
set xlabel "X label" font "/Library/Fonts/Verdana.ttf,20"
plot "data.csv" using 1:2 with lines lc rgb "skyblue" lw 4 notitle;

Then I'll resize the plot from the command line (bash) using:

mogrify -geometry 50% myplot.png

or

convert -geometry 50% myplot.png myplot-small.png

The smoothing done when downsampling lowers apparent precision in addition to making the graph look better. This isn't really a problem, because if you need the precision, you will probably be linking the small plot to a larger version or the original data.

An alternative is to plot using the PostScript terminal, then convert to PNG. This has the advantage that you already have a PS file to link to.

©2015 Schutt Design (Luke & Noel Schutt).
Contact us using one of our first names at schuttdesign dot net.