71

How do I draw different types of lines on gnuplot? I got to draw different colors. My script joins several files and I think it is why the lines are not dash. Only two of four are dashed. Thanks Felipe

#!/usr/bin/gnuplot

set grid
set title 'Estado dos arquivos no BTRIM com peers de comportamento condicionado'
set xlabel 'Tempo discreto'
set ylabel 'Quantidade de arquivos'
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pi -1 ps 1.0
set style line 2 lc rgb '#dd181f' lt 9 lw 2 pi -1 ps 1.0
set style line 3 lc rgb '#29c524' lt 6 lw 2 pi -1 ps 1.0
set style line 4 lc rgb '#7D72F9' lt 7 lw 2 pi -1 ps 1.0
set style line 5 lc rgb '#000000' lt 8 lw 2 pi -1 ps 1.0

set termoption dashed
#set pointintervalbox 0
#set boxwidth 0.1
#set style fill solid

plot '<paste ../00/StatisticNormal.txt ../01/StatisticNormal.txt ../02/StatisticNormal.txt  ../03/StatisticNormal.txt ../04/StatisticNormal.txt ../05/StatisticNormal.txt ../06/StatisticNormal.txt ../07/StatisticNormal.txt ../08/StatisticNormal.txt ../09/StatisticNormal.txt' smooth unique with line ls 1 title 'Normais', \
'<paste ../00/StatisticVogue.txt ../01/StatisticVogue.txt ../02/StatisticVogue.txt ../03/StatisticVogue.txt ../04/StatisticVogue.txt ../05/StatisticVogue.txt ../06/StatisticVogue.txt ../07/StatisticVogue.txt ../08/StatisticVogue.txt ../09/StatisticVogue.txt' smooth unique with line ls 2 title 'na Moda', \
'<paste ../00/StatisticPopular.txt ../01/StatisticPopular.txt ../02/StatisticPopular.txt ../03/StatisticPopular.txt ../04/StatisticPopular.txt ../05/StatisticPopular.txt ../06/StatisticPopular.txt ../07/StatisticPopular.txt ../08/StatisticPopular.txt ../09/StatisticPopular.txt' smooth unique with line ls 3 title 'Populares', \
'<paste ../00/StatisticRarity.txt ../01/StatisticRarity.txt ../02/StatisticRarity.txt ../03/StatisticRarity.txt ../04/StatisticRarity.txt ../05/StatisticRarity.txt ../06/StatisticRarity.txt ../07/StatisticRarity.txt ../08/StatisticRarity.txt ../09/StatisticRarity.txt' smooth unique with line ls 4 title 'Raros'

pause -1
Felipe
  • 7,013
  • 8
  • 44
  • 102
  • So was that your solution? If you use `lc` in a line style definition, the `lt` part is only to choose the dash type. This depends on the terminal. To see the supported dash types, and with which linetype they are associated with, just use the `test` command, like e.g. `set terminal pngcairo dashed; set output 'test.png'; test; set output` or similar with any other terminal type. – Christoph Oct 16 '13 at 20:48

1 Answers1

204

Until version 4.6

The dash type of a linestyle is given by the linetype, which does also select the line color unless you explicitely set an other one with linecolor.

However, the support for dashed lines depends on the selected terminal:

  1. Some terminals don't support dashed lines, like png (uses libgd)
  2. Other terminals, like pngcairo, support dashed lines, but it is disables by default. To enable it, use set termoption dashed, or set terminal pngcairo dashed ....
  3. The exact dash patterns differ between terminals. To see the defined linetype, use the test command:

Running

set terminal pngcairo dashed
set output 'test.png'
test
set output

gives:

enter image description here

whereas, the postscript terminal shows different dash patterns:

set terminal postscript eps color colortext
set output 'test.eps'
test
set output

enter image description here

Version 5.0

Starting with version 5.0 the following changes related to linetypes, dash patterns and line colors are introduced:

  • A new dashtype parameter was introduced:

    To get the predefined dash patterns, use e.g.

    plot x dashtype 2
    

    You can also specify custom dash patterns like

    plot x dashtype (3,5,10,5),\
         2*x dashtype '.-_'
    
  • The terminal options dashed and solid are ignored. By default all lines are solid. To change them to dashed, use e.g.

    set for [i=1:8] linetype i dashtype i
    
  • The default set of line colors was changed. You can select between three different color sets with set colorsequence default|podo|classic:

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • 19
    This is a very useful post – mahmood Jul 25 '14 at 13:06
  • 3
    @Phonon you can define more linetypes and then use `set linetype cycle 20` – Christoph Jun 02 '15 at 18:21
  • 2
    Thanks, but how do you define more linetypes? – Ellie Jun 02 '15 at 18:28
  • 4
    `set linetype 10 lc rgb '#4488bb' dt (5, 5, 10, 10)`, `set linetype 11 ...` and so on – Christoph Jun 02 '15 at 18:34
  • 1
    Link for adding dashed lines in to termtype x11 gnuplot 4.6 here: https://lists.gnu.org/archive/html/octave-maintainers/2012-12/msg00363.html After following this I see dashed lines in the termtype x11 test. – jgreve May 22 '16 at 18:52
  • 1
    It would be helpful to get at least a warning message from gnuplot about png terminal not supporting dashed lines... Switching to pngcairo did the trick. – trygub Jun 05 '17 at 12:37
  • 1000x thanks for the "test" command. I've been using gnuplot for >25 years now but I never came across this one. This would have saved me hours in trying different line types/styles etc. – fieres Sep 21 '22 at 06:39