Gnuplot - cannot change colors of bars - colors

Given dataset:
0 t1 0.52
1 t2 0.66
2 t3 0.58
3 t4 0.57
4 t5 0.68
5 t6 0.61
6 t7 0.55
7 t8 0.52
8 t9 0.58
9 t10 0.50
10 t11 0.59
I cannot manage to get the colors of the bars to change. What I'm trying below is to color green the highest score which happens on line 4. Please have a look over the below:
set terminal postscript eps enhanced 20
set output "edscore2_joint.eps"
set style line 1 lc rgb "#5F9EA0"
set style line 2 lc rgb "#DC143C"
set style line 3 lc rgb "green"
set yrange [0:1]
set ylabel "ed_{score}"
set xlabel "Technique"
set style fill solid
set boxwidth 0.5
set xtics rotate by -45
plot "edscore2_joint.dat" using 1:3:xtic(2) with boxes ls 1 fillstyle pattern 1 notitle ,\
"edscore2_joint.dat" every ::4::4 using 1:3:xtic(2) with boxes ls 3 fillstyle pattern 2 notitle ,\
"edscore2_joint.dat" using 1:($3+0.05):3 with labels notitle

The terminal postscript is monochrome by default. Use either the option color, or, if you have a recent enough gnuplot version, use the terminal epscairo.

Related

Plot a error bar as shaded region in GNUPLOT

I have plotted a graph (X-top axis, Y-bottom axis) with fsteps function in Gnuplot. Next, I tried to add an error bar as a shaded region(transparent) to the graph, but unable to plot it on the graph. Below is the code so far I have tried and also attached the graph.
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [2.5:4.8]
set yrange [314:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
set style fill transparent solid 0.25
set style fill noborder
plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
'MAN.outmd' using 1:2 lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,\
'MAN.outmd' using 1:($2-$3):($2+$3) with filledcurve lc "blue" notitle,
Example Data for file MAN.outmd X Y Z(Error)
0 3 0
0.4475 3.1 0
0.4475 3.5 0
2.6738 3.6 0.0552
2.6738 5 0.0552
3.8441 5.1 0.0592
3.8441 8 0.0592
3.6302 8.1 0.0395
3.6302 15.935 0.0395
4.5176 15.1 0.041
4.5176 113.296 0.041
4.2443 113.3 0.1024
4.2443 214 0.1024
4.4584 214.1 0.1077
4.4584 314 0.1077
I want output should be as given below (example)
gnuplot can easily fill the area between two "horizontal" curves (i.e. unique x-values), but as far as I know, not between two vertical curves. However, gnuplot can fill some enclosed areas. So, the workaround is to create datapoints which surround the area to be shaded. For this, you "plot" the data into a datablock, once "forward" with x-dx and once "backwards" with x+dx. This can be done easiest if you have the data already in a datablock, because then you can easily loop the data forward and backwards. In case you have your data in a file, see here: gnuplot: load datafile 1:1 into datablock
Code:
### fill between vertical curves
reset session
$Data <<EOD
0 3 0
0.4475 3.1 0
0.4475 3.5 0
2.6738 3.6 0.0552
2.6738 5 0.0552
3.8441 5.1 0.0592
3.8441 8 0.0592
3.6302 8.1 0.0395
3.6302 15.935 0.0395
4.5176 15.1 0.041
4.5176 113.296 0.041
4.2443 113.3 0.1024
4.2443 214 0.1024
4.4584 214.1 0.1077
4.4584 314 0.1077
EOD
# create datablock with circumference of shaded area
set print $XErrorFill
do for [i=1:|$Data|] {
print real(word($Data[i],1))-real(word($Data[i],3)), real(word($Data[i],2))
}
do for [i=|$Data|:1:-1] {
print real(word($Data[i],1))+real(word($Data[i],3)), real(word($Data[i],2))
}
set print
set yrange [:] reverse
set style fill noborder
plot $XErrorFill u 1:2 w filledcurves lc "light-grey" notitle, \
$Data u 1:2 w l lw 1.5 lc rgb "red" notitle
### end of code
Result:

gnuplot: How to create colored grid regions, not just colored grid lines?

I am using "gnuplot 5.2 patchlevel 2". I am trying to create background grid colored-columns or colored-areas like the picture below. So far, I am only able to color the grid-lines. But I want to color the grid areas. What is the best way? Here is my code:
set terminal svg
set output 'out.svg'
set key off
set xlabel 'X'
set ylabel 'Y'
set title 'Data'
set grid
set grid xtics lw 0.25 lc rgb "#ff0000" # line only, but I want to color the whole area
#unset grid
#set grid ytics lt 0 lw 1 lc rgb "#0000ff"
set xrange [0:4]
set yrange [0:100]
set tics scale 0.5
set xtics nomirror
set ytics nomirror
set style fill solid noborder
set linetype 1 lc rgb 'red' lw 0.35
set linetype 2 lc rgb '#009900'
set linetype 3 lc rgb 'black' lw 0.5
set boxwidth 0.5 relative
set style fill solid border lc rgb "black"
plot "data.txt" using 1:2:4:3:5:($5 < $2 ? 1 : 2) linecolor variable with candlesticks, \
"data.txt" using 1:6 with lines lt 3, \
"data.txt" using 1:5:7 with filledcurves fs transparent solid 0.3 lc rgb "blue"
And here is my sample data.txt file for the plotting:
1 10 30 5 20 23 29
2 25 45 10 30 34 37
3 30 50 20 25 47 53
You could use a dummy function like [x=0:16:1] '+' us (x/2):(100/(int(x)%4!=1)) with filledcurves x1.
Every fourth point generates a NaN and interrupts the curve.
$data <<EOD
1 10 30 5 20 23 29
2 25 45 10 30 34 37
3 30 50 20 25 47 53
5 10 30 5 20 23 29
7 25 45 10 30 34 37
8 30 50 20 25 47 53
EOD
set style fill solid noborder
set linetype 1 lc rgb 'red' lw 0.35
set linetype 2 lc rgb '#009900'
set linetype 3 lc rgb 'black' lw 0.5
set boxwidth 0.5 relative
set style fill solid border lc rgb "black"
plot sample [x=0:16:1] '+' us (x/2):(100/(int(x)%4!=1)) with filledcurves x1 fc rgb "#EEEEEE",\
$data using 1:2:4:3:5:($5 < $2 ? 1 : 2) linecolor variable with candlesticks, \
$data using 1:6 with lines lt 3, \
$data using 1:5:7 with filledcurves fs transparent solid 0.3 lc rgb "blue"
This function could be also assigned to the y2 axis with fixed y2range, which might be more handy for interactive plots with zooming.

How to demonstrate LaTeX formula with Gnuplot?

I have attempted to demonstrate a LaTeX formula with Gnuplot 5.0.
But I found that some LaTeX commands are unavailable.
This is my Gnuplot Code:
set termoption enhanced
set title "Title test^a \alpha $\alpha$" font "CMU-Serif, 18"
set xlabel "Month"
set ylabel "Precipitation (mm)"
set xrange [0.5: 12.5]
set xtics 1,1,12
set key
set pointintervalbox 2
plot "08_Data.dat" using 1:2 with linespoints \
linecolor "#FF7800" linewidth 2 pointtype 7 pointsize 0.75 pointinterval -1 \
title "Beijing",\
"08_Data.dat" using 1:3 with linespoints \
linecolor "#00A0DC" linewidth 2 pointtype 7 pointsize 0.75 pointinterval -1 \
title "Shanghai",
set output
pause (-1)
As a result, the LaTeX command test^a works well but the LaTeX \alpha and $\alpha$ don't work:
This is the file: 08_Data.dat :
1 2.5 38.1
2 5.1 58.4
3 10.2 81.3
4 25.4 101.6
5 27.9 114.3
6 71.1 152.4
7 175.3 129.5
8 182.9 132.1
9 48.3 154.9
10 17.8 61.0
11 5.1 50.8
12 2.5 35.6
set term tikz standalone size 7cm, 3cm fontscale 0.6
set ylabel '{\LaTeX\ -- $ \gamma $}'
set xlabel '{\LaTeX\ -- $ x $}'
set output 'example.tex'
plot [0:1] gamma(x) title '$ \gamma(x) $'
unset output
!pdflatex example
Have you tried to directly type in the alpha character in the gnuplot code? I guess gnuplot understands UTF-8.
set title "test^a α α" font "CMU-Serif, 18"
plot x
Result:

gnuplot: make only one border thicker in a surface plot

So I am trying to plot a three-dimensional sphere on the first quadrant like this --
I want to make the line BC thicker/bold from the rest. How do I do that?
This is my gnuplot script:
set term wxt 0
set parametric
set urange[0:0.5 * pi]
set vrange[0:0.5 * pi]
r = 1
fx(v,u) = r * cos(v) * cos(u)
fy(v,u) = r * sin(u) * cos(v)
fz(v) = r * sin(v)
set label 1 "A" font "Arial, 15" front at 0.000, 0.900, -0.050
set label 2 "B" font "Arial, 15" front at 0.050, 0.000, 0.900
set label 3 "C" font "Arial, 15" front at 1.050, 0.105, 0.000
set pm3d depthorder border linetype 1 linewidth 0.50
set style fill transparent solid 0.50 border
set palette
set hidden3d
unset colorbox
splot fx(u,v), fy(u,v), fz(u) w pm3d, \
"< echo '0.000 0.000 1.000'" with points pt 7 ps 0.75 lc rgb 'black', \
"< echo '0.000 1.000 0.000'" with points pt 7 ps 0.75 lc rgb 'black', \
"< echo '1.000 0.000 0.000'" with points pt 7 ps 0.75 lc rgb 'black'
set term push
set term pdf enhanced mono
set output "b1.pdf"
replot
unset output
set term pop
system(sprintf("%s", "pdfcrop b1.pdf b1.pdf"))
well, simply plot the line B,C again with lines.
And what is this line in parametric representation? fx(u,0), fy(0,0), fz(u)
splot fx(u,v), fy(u,v), fz(u) w pm3d, \
fx(u,0), fy(0,0), fz(u) w l lw 3 lc rgb "red"
Which gives you something like this... (well, different terminal...)

Adding vertical marker lines in gnuplot for histogram

There are a few instructions to get vertical lines in gnuplot when plotting functions. Like using the set arrow function. I need this functionality for a histogram and it turns out the histogram has different position of 0.0 on X axis. In my case the X axis markers are just strings from the data file.
When plotting the histogram it would be so nice to have the mean, +-3sigma and maybe the X=0 point marked by vertical lines from top to bottom of the plot in fat colored solid lines.
My histogram code:
set boxwidth 1.0 absolute
set style line 1 lc rgb 'skyblue'
set style fill solid border lt -1
set style data histogram
set style histogram clustered gap 0.0
set xtics in rotate by 90 offset first +0.5,0 right
set xlabel
set ylabel 'Count'
set terminal unknown
plot 'histo.raw' using 3
set title 'data'
set yrange [0:GPVAL_DATA_Y_MAX*1.2]
set term X11
plot 'histo.raw' using 3:xtic(2) ls 1 title columnheader(1)
set arrow 1 from 0.0,0.0 to 0.0,GPVAL_DATA_Y_MAX*1.2 nohead
My data:
"data"
0 "-INF -> -5.0" 0 0.00
1 " -5.0 -> -4.5" 0 0.00
2 " -4.5 -> -4.0" 2 0.03
3 " -4.0 -> -3.5" 4 0.06
4 " -3.5 -> -3.0" 3 0.05
5 " -3.0 -> -2.5" 5 0.08
6 " -2.5 -> -2.0" 19 0.30
7 " -2.0 -> -1.5" 49 0.78
8 " -1.5 -> -1.0" 193 3.07
9 " -1.0 -> -0.5" 527 8.39
10 " -0.5 -> +0.0" 1289 20.53
11 " +0.0 -> +0.5" 1878 29.90
12 " +0.5 -> +1.0" 1411 22.47
13 " +1.0 -> +1.5" 636 10.13
14 " +1.5 -> +2.0" 178 2.83
15 " +2.0 -> +2.5" 56 0.89
16 " +2.5 -> +3.0" 17 0.27
17 " +3.0 -> +3.5" 9 0.14
18 " +3.5 -> +4.0" 4 0.06
19 " +4.0 -> +4.5" 0 0.00
20 " +4.5 -> +5.0" 0 0.00
21 " +5.0 -> +INF" 0 0.00
The set arrow function puts the line in the wrong spot.
set arrow 1 from 0.0,0.0 to 0.0,GPVAL_DATA_Y_MAX*1.2 nohead
In this data
mean= 0.2743
sigma= 0.7491
Thanks for your ideas.
Gert
I found that the histogram bars are defining their own X coordinates counting left to right. As I have 22 data rows for 22 histogram bars adding 11.0 to the line position does the job.
set boxwidth 1.0 absolute
set style line 1 lc rgb 'skyblue'
set style fill solid border lt -1
set style data histogram
set style histogram clustered gap 0.0
set xtics in rotate by 90 offset first +0.5,0 right
set xlabel
set ylabel 'Count'
set terminal unknown
plot 'histo.raw' using 3
set title 'data'
set yrange [0:GPVAL_DATA_Y_MAX*1.2]
set terminal png size 1200,800
set output 'histo.png'
mean= +0.2743
sdev= +0.7491
lboffs= 0.2
set arrow from 11.0 + mean,0.0 to 11.0 + mean ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "dark-green"
set arrow from 11.0 + mean - 3 * sdev,0.0 to 11.0 + mean - 3 * sdev ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "red"
set arrow from 11.0 + mean + 3 * sdev,0.0 to 11.0 + mean + 3 * sdev ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "red"
set arrow from 11.0,0.0 to 11.0,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "blue"
set label "Mean" at 11.0 + mean + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "dark-green"
set label "+3%" at 11.0 + mean + 3 * sdev + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "red"
set label "-3%" at 11.0 + mean - 3 * sdev + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "red"
plot 'histo.raw' using 3:xtic(2) ls 1 title columnheader(1)
set output
set term X11

Resources