5

Can you help me please? I want change one line type to dotted. I use these comannds:

gnuplot> set terminal png size 750,210 nocrop butt font "/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf" 8
gnuplot> set output "/root/data.png"
gnuplot> set xdata time
gnuplot> set timefmt "%Y-%m-%d"
gnuplot> set format x "%b %d"
gnuplot> set ylabel "item1"
gnuplot> set y2label "item2"
gnuplot> set y2tics
gnuplot> set datafile separator "|"
gnuplot> plot "/root/results.txt" using 1:2 title "item1" w lines lt 4, "/root/results.txt" using 1:3 title "item2" with lines

But I allways get only magenta color line. I have used Version 4.6 patchlevel 0. Thanks for replies.

Mato
  • 225
  • 1
  • 6
  • 10
  • http://stackoverflow.com/q/8106872/1030675 – choroba Jan 23 '14 at 10:56
  • @choroba, thanks. But How I set line style in plot drawing syntax please? – Mato Jan 23 '14 at 12:21
  • Whats wrong with `plot x lt 4, x**2 lt 3`? But also `plot x lt 4, x**2` should work, but in the second case `linetype 2` is automatically selected. – Christoph Jan 23 '14 at 12:40
  • @Christoph Thanks. But when I used: gnuplot> set style line 1 lt 2 lc 8 gnuplot> set style line 1 lt 1 lc 7 gnuplot> plot "/root/dataASD.txt" using 1:2 title "item1" with lines, "/root/dataASD.txt" using 1:3 title "item2" with lines I get the same rusult still... Lines are solid, first is red and second is green... – Mato Jan 23 '14 at 14:04
  • Yes, because with `set style line` you specify a line *style*, which you select with e.g. `linestyle 1`. By default line *type* is used when nothing is specified. – Christoph Jan 23 '14 at 19:24
  • Same here. I can say lw 4 and it works, but lt 2 does not. I can't seem to draw anything but lines. – SDsolar Jan 04 '17 at 10:13

2 Answers2

5

There are several ways to change the line colors using set commands:

  1. Define line styles:

    set style line 1 linetype 1 linecolor 7
    set style line 2 linetype 1 linecolor rgb "#dd7700"
    plot x linestyle 1, x**2 linestyle 2
    

    You must explicitely specify which line style is used.

  2. Choose and increment over line style instead of line type if nothing is specified:

    set style line 1 linetype 1 linecolor 7
    set style line 2 linetype 1 linecolor rgb "#dd7700"
    set style increment user
    plot x, x**2
    
  3. Redefine the default line type (introduced in version 4.6.0):

    set linetype 1 linecolor 7
    set linetype 2 linetype 1 linecolor rgb "magenta"
    plot x, x**2
    

    Beware, that unlike line styles, redefinitions by set linetype are persistent; they are not affected by reset. To reset them you must use set linetype 1 default.

So a minimal plotting script could look like:

reset
set terminal pngcairo dashed monochrome
set output "/root/data.png"
set xdata time
set timefmt "%Y-%m-%d"
set format x "%b %d"
set datafile separator "|"
set style data lines

plot "/root/results.txt" using 1:2 linetype 1, "" using 1:3 linetype 3
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Thanks. But now how will look my correct plot command please? If I apllied set 1, when I use: plot "/root/dataASD.txt" linestyle 1 using 1:2 title "item1" with lines, "/root/dataASD.txt" linestyle 2 using 1:3 title "item2" with lines I get error messange: Need full using spec for x time data. – Mato Jan 23 '14 at 20:50
  • See the edited answer for a complete script. This should work fine and doesn't change anything about how the time data is handled. Be sure to include a `reset` before executing the code to avoid problems with previous settings in an interactive session. – Christoph Jan 24 '14 at 09:17
  • Thanks. It works. But second line does not dotted. I set linetype 4. Linetype 4 should be dotted - http://www2.yukawa.kyoto-u.ac.jp/~akira.ohnishi/Lib/gnuplot.html But I have still solid line. Why please? I need one line dotted, because graph will be print with monochrome print... – Mato Jan 24 '14 at 09:51
  • Ups, I sticked to the 'magenta' but haven't noticed the 'dotted' part! You must use the `pngcairo` terminal with the `dashed` option for this, with `png` (i.e. libgd) you can't get dashed lines. Use e.g. `set terminal pngcairo dashed monochrome; set output 'test.png'; plot "/root/results.txt" using 1:2 lt 1 , "" using 1:3 lt 3` to get black, dashed lines, see also [Gnuplot line types](http://stackoverflow.com/a/19420678/2604213). – Christoph Jan 24 '14 at 10:01
  • So If I use: gnuplot> set terminal pngcairo dashed monochrome Terminal type set to 'pngcairo' Options are ' background "#ffffff" fontscale 1.0 monochrome dashed size 640, 480 ' gnuplot> set output 'bodkaD1.png' gnuplot> set xdata time gnuplot> set timefmt "%Y-%m-%d" gnuplot> set format x "%b %d" gnuplot> set datafile separator "|" gnuplot> plot "/root/dataASD.txt" using 1:2 title "item1" lt 1, "/root/dataASD.txt" using 1:3 title "item2" lt 3 I get graph from scattered plus and stars symbols. – Mato Jan 24 '14 at 11:02
  • I need graph with line, that will be for example from stras symbols... In your picture for example lien 17... – Mato Jan 24 '14 at 11:02
  • Thats what `set style data lines` is for, or use `with lines` after plotting. Please use the *complete* script at the end of the answer, thats why I posted it! – Christoph Jan 24 '14 at 11:35
0

On the X-11 terminal I have no trouble changing the line color but have had no success changing line types to include dotted and/or dashed lines.

SDsolar
  • 2,485
  • 3
  • 22
  • 32
  • 4
    With gnuplot 5 you must use `dashtype` to get dashed or dotted lines, see e.g. http://stackoverflow.com/a/19420678/2604213, http://stackoverflow.com/a/28438812/2604213 or http://stackoverflow.com/a/29950759/2604213 for actual examples and explanations of it syntax. – Christoph Jan 10 '17 at 15:35
  • Thank you very much. I see what they are saying. Will test it out. Upvote for your comment. – SDsolar Jan 17 '17 at 07:13