Tuesday 3 July 2018

Dash it all: Custom line styles

Lines in gnuplot can come in different styles;  solid lines, dashed lines, or dotted lines, for example.  Probably the easiest way to set these is to use the dashtype pattern specifier, in gnuplot 5 and above.  The gnuplot help guide says:

       dashtype "pattern"  # string containing a combination of the characters
                           # dot (.) hyphen (-) underscore(_) and space.

and some examples are shown below:


set term pdfcairo font "Chalkduster,15"
set out 'dashes.pdf'
set key samplen 12 opaque box
PI = acos(-1.)
set xrange [0:2*PI]
plot sin(x) dashtype '-' lw 3 t 'Sin(x)', \
  sin(2*x) dashtype '.' lw 3 t 'Sin(2x)', \
  sin(3*x) dashtype '. -   _' lw 3 t 'Sin(3x)', \
0 not

Here we set up a pdf output, with a somewhat silly choice of font -- and one that I checked existed on my system.  I set up the key to include a very long length line in the legend, because I am making up an example with a complicated dash type.

The plot line plots the functions sin(nx), n=1,2,3 and assigns each a different dash type:  '-', '.' and '. -  _'for dashes, dots, and a more complicated pattern.  The results are shown below:


1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete