How to change the pattern of the last column ?
Here is the script:
set ylabel "Accuracy"
set style fill solid border
set style line 1 lt 1 lc rgb "blue"
set style line 2 lt 1 lc rgb "green"
plot "orientation.csv" u (column(0)):2:(0.5):($2!=0.875?1:2) title "" w boxes lc variable fs pattern 1;
Unfortunately there is no option fillstyle variable. You must split the plot command in two parts: one for each pattern:
set boxwidth 0.5 absolute
unset key
set style fill solid border
set style line 1 lt 1 lc rgb "blue"
set style line 2 lt 1 lc rgb "green"
plot "orientation.csv" u 0:($2 != 0.875 ? $2 : 1/0) with boxes ls 1 fs pattern 1,\
"" u 0:($2 != ? 1/0 : $2) with boxes ls 2 fs pattern 2
Related
I have two functions and want to fill the area between them
enset xlabel "x"
set ylabel "y"
set yrange[-20:30]
set xrange[-30:120]
plot 10*sin(0.2*x) title "f(x) = 10 sin(0.2x)" lw 2
replot sqrt(x) title "g(x) = sqrt(x)" lw 2
replot [0:73.4] -sqrt(x)+10*sin(0.2*x) with boxes title "Área de intersección"
But I didn't get what i expected. How can I fill this space correctly?
f(x) = 10*sin(0.2*x)
g(x) = sqrt(x)
set key opaque box
set xrange [0:73.4]
plot '+' using 1:(f(x)):(g(x)) with filledcurves between fillcolor "grey" notitle, \
f(x) with lines lt 2 lw 2 title "f(x)", \
g(x) with lines lt 3 lw 2 title "g(x)"
Adjust titles, colors, linewidth as you like.
I would like to make a gnuplot graph with one full bar and another one stacked.
The data is something like
x data E M L
[10,20) 0.000000 1.081916 2.0958133 5.473606
[20,40) 0.000000 2.331769 2.1402838 4.528341
[40,80) 3.262375 2.201788 1.3499280 3.023847
>80 2.368121 2.132216 0.7322889 2.610368
where E, M and L are the three "green" components.
I have tried to do something like
set style data histograms
set style histogram rowstacked
#set style histogram cluster gap 1
set style fill solid
...
plot newhistogram, "size_class_data/tree_paracou.txt" using 2:xticlabel(1) linecolor rgb data_color title "Model",\
newhistogram, '' using 3:xticlabel(1) linecolor rgb early_color title "d",\
'' using 4 linecolor rgb mid_color title "g",\
'' using 5 linecolor rgb late_color title "f"
but the two graphs lie on two different parts of the x axis.
The newhistogram command has an option at for setting the coordinate of the first box.
In you case you can fix the boxwidth, and start the second histogram at 0 + boxwidth:
set style data histograms
set style histogram rowstacked
set style fill solid
set boxwidth 0.33 absolute
plot "foo.dat" using 2:xticlabel(1) skip 1 linecolor rgb "black" title "Model",\
newhistogram at 0.33, '' using 3 skip 1 linecolor rgb "red" title "d",\
'' using 4 skip 1 linecolor rgb "green" title "g",\
'' using 5 skip 1 linecolor rgb "blue" title "f"
I have a very simple dataset:
Critical 2
High 18
Medium 5
Low 14
Creating a bar chart in gnuplot out of this dataset is easy, but all the bars are the same colour. I want to have it so that Critical is black, high is red, etc, but there seem to be hardly any online tutorials for doing this.
Can anyone point me in the right direction?
set xrange [-.5:3.5]
set yrange [0:]
set style fill solid
plot "<sed 'G;G' test.dat" i 0 u (column(-2)):2:xtic(1) w boxes ti "Critical" lc rgb "black",\
"<sed 'G;G' test.dat" i 1 u (column(-2)):2:xtic(1) w boxes ti "High" lc rgb "red" ,\
"<sed 'G;G' test.dat" i 2 u (column(-2)):2:xtic(1) w boxes ti "Medium" lc rgb "green",\
"<sed 'G;G' test.dat" i 3 u (column(-2)):2:xtic(1) w boxes ti "Low" lc rgb "blue"
This takes sed and triple spaces your file so that gnuplot sees each line as a different dataset (or "index"). You can plot each index separately using index <number> or i <number> for short as I have done. Also, the index number is available as column(-2) which is how we get the boxes properly spaced.
Possibly a slightly more clean (gnuplot only) solution is using filters:
set xrange [-.5:3.5]
set yrange [0:]
set style fill solid
CRITROW(x,y)=(x eq "Critical") ? y:1/0
HIGHROW(x,y)=(x eq "High") ? y:1/0
MIDROW(x,y) =(x eq "Medium") ? y:1/0
LOWROW(x,y) =(x eq "Low") ? y:1/0
plot 'test.dat' u ($0):(CRITROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "black" ti "Critical" ,\
'' u ($0):(HIGHROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "red" ti "High" ,\
'' u ($0):(MIDROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "green" ti "Medium" ,\
'' u ($0):(LOWROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "blue" ti "Low"
This solution also doesn't depend on any particular ordering in your datafile (which is why I prefer it slightly to the other solution. We accomplish the spacing here with column(0) (or $0) which is the record number in the dataset (in this case, the line number).
Here is how you can do this using the linecolor variable option.
If you know, that the lines are always in the same, known order, you can use the row number (zeroth column, $0) as linetype index:
set style fill solid noborder
set linetype 1 lc rgb 'black'
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
set yrange [0:*]
unset key
plot 'alerts.txt' using 0:2:($0+1):xtic(1) with boxes linecolor variable
If the order may vary, you can use a gnuplot-style indexing function, which determines the index of the warning level from a string with space-separated words:
alerts = 'Critical High Medium Low'
index(s) = words(substr(alerts, 0, strstrt(alerts, s)-1)) + 1
set style fill solid noborder
set linetype 1 lc rgb 'black'
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
set yrange [0:*]
unset key
plot 'alerts.txt' using 0:2:(index(strcol(1))):xtic(1) with boxes linecolor variable
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
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).