2010/11/25

Setting a dashed line style on a PDF terminal in gnuplot

Everyone who's tried to include a gnuplot graph with several curves on the same graph in a B&W printed report has noticed that by default, all linestyles for the pdf terminal type look the same in black and white.

You can check for yourself by giving gnuplot the commands

gnuplot> set terminal pdf monochrome
gnuplot> set output "graph.pdf"
gnuplot> test
gnuplot> unset output

This will create a new file called graph.pdf containing all possible linestyles on the right. You'll notice they all look exactly the same.

The solution for this is kind of obvious but pretty much impossible to find unless you know what you're looking for. It's possible to enable the use of dashed lines by giving an extra parameter to the set terminal pdf command. Try the commands

gnuplot> set terminal pdf monochrome dashed
gnuplot> set output "graph.pdf"
gnuplot> test
gnuplot> unset output

and you'll see dashed lines suddenly appearing on the right. You can use them like this:
gnuplot> set terminal pdf monochrome dashed
gnuplot> set output "graph.pdf"
gnuplot> plot x^2 ls 1, x^3 ls 2, x^4 ls 3
gnuplot> unset output

To set linestyle 1 (look at the test output to see what linestyle one looks like) for x^2, linestyle two for x^3 and finally linestyle three for x^4.

2 comments:

  1. Thank you! Just what I needed and, as you say, otherwise impossible to find.

    ReplyDelete