gnuplot point color wrong - colors

In this example, the point color(blue) of the 3. plot differs from the test output(green) - why is that? (my default terminal is aqua, but it is the same with e.g. png)
plot [0:4]\
'-' title 'pt1' with points pt 1,\
2*x title 'lt1' with lines lt 1,\
'-' title 'pt2' with points pt 2,\
3*x title 'lt2' with lines lt 2
1 1
2 5
end
1 3
3 7
end
by changing the order of the plots, the color changes:
plot [0:4]\
'-' title 'pt1' with points pt 1,\
'-' title 'pt2' with points pt 2,\
2*x title 'lt1' with lines lt 1,\
3*x title 'lt2' with lines lt 2
1 1
2 5
end
1 3
3 7
end

User sfeam on SourceForge provides the answer:
point type does not control color. It is the third plot, and you have
not instructed otherwise, so it gets the color of linetype 3 (blue).
Apparently the color of lines plot is set by the number of previous lines
plots, while the color of points plot is set by the number of all previous
plots.
Both can be controlled by linecolor or lc.

Related

Gnuplot: "Complementary" dashed lines

I would like to plot "complementary" dashed lines. What I mean is the following: I have three curves that are identical in a certain range of x values but different outside this range. Of course, if I simply plot solid lines on top of each other, I will only see the topmost one (in the range where they are identical). So, I would like to plot them as dashed lines:
1st line: dash-space-space-dash-space-space...
2nd line: space-dash-space-space-dash-space...
3rd line: space-space-dash-space-space-dash...
Plotting them on top of each other should produce a solid lines with alternating colors (of the three line types).
The most obvious way to achieve this is with the new dashtypes, for example:
plot x dt "- ",x dt " - ",x dt " -"
However, the leading blank is ignored. Also, a definition such as (20,20) does not work because the order of values is always "solid length,emptyspace length". If there were a way to invert this order, the problem could be solved easily.
(By the way, in the case of only two curves, the solution is simple: plot the first as solid and the second as dashed.)
Any ideas?
You are probably looking for something like this:
### different shifted dashed lines
reset session
plot x, \
0 w l lw 3 lc rgb "red" dt (20,40) notitle, \
0 w l lw 3 lc rgb "web-green" dt (0,20,20,20) notitle, \
0 w l lw 3 lc rgb "blue" dt (0,40,20,0) notitle
### end of code
Addition:
with the following code the result should be the same (or let's say similar) in wxt, qt, postscript, pngcairo (cannot test x11). Well, the dash length is different depending on the terminal (see https://stackoverflow.com/a/55628295/7295599)
### different shifted dashed lines
reset session
# set term wxt
# set term qt
set term pngcairo
set output "DashedLines.png"
# set term postscript color
# set output "DashedLines.eps"
plot x, \
0 w l lw 3 lc rgb "blue" dt 1 notitle, \
0 w l lw 3 lc rgb "web-green" dt (40,20) notitle, \
0 w l lw 3 lc rgb "red" dt (20,40) notitle
set output
### end of code

GNUplot - plot data file (simple X and Y columns) - setting suitable color and scale on a figure

I have a simple file with two columns:
1 0.005467
2 0.005333
3 0.005467
4 0.005467
5 0.005600
6 0.005600
7 0.005467
8 0.005467
In the first column I have the x-axis values, while on the second column I have y-axis values. I would like to plot a figure of this data. I wrote a gnuplot script for this:
#!/usr/bin/gnuplot
set xlabel "test"
set ylabel "value"
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
set autoscale
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
set output 'out.eps'
plot 'data.txt' using 2:1 w points title "tests"
And, the output:
But of course, as a newbie in gnuplot, I have some troubles:
How to change the crosses on the fingure into dots?
How to change the color of the dots, to let's say, red? ( my command in my gnuplotscript seems not to work at all ...)
For the first test the adequate, accurate, exact value is 0.005467 but on my figure it doesnt look like so... I would like to place the dot on my figure for the first, second, third, (so on) test on the exact place, where is appropriate value.
How to add a grid to my figure? - SOLVED
How to get rid of the ugly text: 'data.txt' using 1:2 and replace it with a legend? - SOLVED
EDIT (SOLVED ISSUE NO 5)
plot 'data.txt' using 1:2 w points title "tests"
EDIT (SOLVED ISSUE NO 4)
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
You should read a bit in the documentation about all your commands!
Several remarks:
If you want colored points, you shouldn't use the mono (i.e. the monochrome) option, but rather color.
Your definition of the line style is correct, but in order to use it you must use linestyle 1 when plotting. Otherwise the linetype 1 is used. Compare:
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot x, 2*x linestyle 1
In order to see all the dots of a terminal, use the test command:
set terminal postscript eps enhanced color dashed lw 1 'Helvetica' 14
set output 'test.eps'
test
set output
You see, that for filled dots you must use pt 7.
I'm sure, that the points are shown at the correct values. Use
set ytics add (0.005467)
to see this.

gnuplot - Increase size of point only in legend/key

I have a graph that looks like this:
I want to increase the size of the points in the legend (is it legend or key?) but without increasing the size of the points in the plot.
It's explained better in the picture. Can this be achieved?
First plot nothing with increased symbol size, then plot the data without the key.
gnuplot> plot 1/0 ls 7 lw 6 with points t "0.0", "yourdata" ls 7 notitle
Use the same point style for both of the plots, and rename the first plot key as you wish.
Unless you are using filled circles (pt 7) you may want to adopt this improvement of the Jari's answer which looks better as the points in the key are less fatty and more elegant:
plo 1/0 w p lc 1 pt 1 lw 3 ps 3 t "Data 1", "data1.dat" lc 1 pt 1 notitle,\
1/0 w p lc 3 pt 2 lw 3 ps 3 t "Data 2", "data2.dat" lc 3 pt 2 notitle

gnuplot draw two plots on the same graph with single column data

There are two data files, say data1.txt:
31231
32312
32323
32323
data2.txt:
32323
54223
32456
45321
I want to draw the two plots on the same graph, how can I use gnuplot to realize that? Thank yu very much.
You could get two plots on the same graph in one plot command with two datafile arguments, separated by a comma. For instance
plot [-1:5] 'data1.txt' with points, 'data2.txt' with points
would get you something like this:
This works for me :
reset
set term pngcairo
set output 'wall.png'
set xlabel "Length (meter)"
set ylabel "error (meter)"
set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
set datafile separator ","
set key
set auto x
set xtics 1, 2, 9
set yrange [2:7]
set grid
set label "(Disabled)" at -.8, 1.8
plot "file1.csv" using 1:2 ls 1 title "one" with lines ,\
"file2.csv" using 1:2 ls 2 title "two" with lines ,\
"file3.csv" using 1:2 ls 3 title "three" with lines
set output

Choosing line type and color in Gnuplot 4.0

I have two pairs of datasets, which I need to plot using Gnuplot.
I want the first pair to be plotted in red, one solid and one dashed. The second pair, I want to plot in blue, one solid and one dashed.
I've experimented with set style line several times, but I cannot get this exact behaviour. My last attempt (attached) plots the first pair in red (solid) and the second pair in blue (dotted).
Any help will be greatly appreciated.
set style line 1 lt 1 lw 3 pt 3
set style line 2 lt 1 lw 3 pt 3
set style line 3 lt 3 lw 3 pt 3
set style line 4 lt 3 lw 3 pt 3
plot 'data1.dat' using 1:3 w l ls 1,\
'data1.dat' using 1:4 w l ls 2,\
'data2.dat' using 1:3 w l ls 3,\
'data2.dat' using 1:4 w l ls 4
You need to use linecolor instead of lc, like:
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
"help set style line" gives you more info.
I've ran into this topic, because i was struggling with dashed lines too (gnuplot 4.6 patchlevel 0)
If you use:
set termoption dashed
Your posted code will work accordingly.
Related question:
However, if I want to export a png with:
set terminal png, this isn't working anymore. Anyone got a clue why?
Turns out, out, gnuplots png export library doesnt support this.
Possbile solutions:
one can simply export to ps, then convert it with pstopng
according to #christoph, if you use pngcairo as your terminal (set terminal pngcairo) it will work
You can also set the 'dashed' option when setting your terminal, for instance:
set term pdf dashed
Here is the syntax:
set terminal pdf {monochrome|color|colour}
{{no}enhanced}
{fname "<font>"} {fsize <fontsize>}
{font "<fontname>{,<fontsize>}"}
{linewidth <lw>} {rounded|butt}
{solid|dashed} {dl <dashlength>}}
{size <XX>{unit},<YY>{unit}}
and an example:
set terminal pdfcairo monochrome enhanced font "Times-New-Roman,12" dashed
You might want to look at the Pyxplot plotting package http://pyxplot.org.uk which has very similar syntax to gnuplot, but with the rough edges cleaned up. It handles colors and line styles quite neatly, and homogeneously between x11 and eps/pdf terminals.
The Pyxplot script for what you want to do above would be:
set style 1 lt 1 lw 3 color red
set style 2 lt 1 lw 3 color blue
set style 3 lt 2 lw 3 color red
set style 4 lt 2 lw 3 color blue
plot 'data1.dat' using 1:3 w l style 1,\
'data1.dat' using 1:4 w l style 2,\
'data2.dat' using 1:3 w l style 3,\
'data2.dat' using 1:4 w l style 4`
Edit: Sorry, this won't work for you. I just remembered the line color thing is in 4.2. I ran into this problem in the past and my fix was to upgrade gnuplot.
You can control the color with set style line as well. "lt 3" will give you a dashed line while "lt 1" will give you a solid line. To add color, you can use "lc rgb 'color'". This should do what you need:
set style line 1 lt 1 lw 3 pt 3 lc rgb "red"
set style line 2 lt 3 lw 3 pt 3 lc rgb "red"
set style line 3 lt 1 lw 3 pt 3 lc rgb "blue"
set style line 4 lt 3 lw 3 pt 3 lc rgb "blue"
I know the question is old but I found this very helpful http://www.gnuplot.info/demo_canvas/dashcolor.html . So you can choose linetype and linecolor separately but you have to precede everything by "set termoption dash" (worked for me in gnuplot 4.4).

Resources