I'm new to gnuplot and I want to draw a triple histogram for a set of data of any length.
Here is my code but the line set palette gray seems to have no effect -- everything is still in RGB. What am I missing here?
set terminal pdf enhanced
set output 'out.pdf'
set palette gray
set style data histogram
set style histogram cluster gap 1
set style fill solid 1
set auto x
set yrange [0:*]
plot 'in.dat' using 2:xtic(1) title col, \
'' using 3:xtic(1) title col, \
'' using 4:xtic(1) title col
The set palette command influences only images, pm3d surfaces and if used explicitely with e.g. linecolor palette.
The terminal option monochrome also doesn't help you, because that sets the color of all lines to black and uses different dash patterns.
You can e.g. redefine the color of the linetypes:
set linetype 1 lc rgb 'black'
set linetype 2 lc rgb '#555555'
set linetype 3 lc rgb '#999999'
plot 'in.dat' u 2:xtic(1) t col, '' u 3 t col, '' u 4 t col
Note, that reset doesn't revert this line type changes. For this you must restart gnuplot.
Alternatively, you could also use set terminal pdf monochrome and set style fill pattern.
Related
I have a gnuplot label for my plot
plot f(x) title 'Before(w)' with lines ls 1
In my label there is Before(w). I would like the color of a letter w to be red. How can I do it?
I was able to find code that changes the color of the whole label (http://www.gnuplot.info/demo_4.6/textcolor.html) but it is not what I want.
Thanks.
Working example
set terminal postscript eps size 3.5,2.62 enhanced color \
font 'Helvetica,20' linewidth 2
set output 'plot2.eps'
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2 #(gnuplotting)
f(x) = exp(-x*x)
plot f(x) title 'Before(w)' with lines ls 1
I've got the following data:
# id min 1st quart median 3rd quart max sum std-dev name
1 0.00029 0.02590 0.06331 0.12910 6.50177 1524.58705 0.13483 spec
2 1.50041 1.59762 1.67226 1.79827 13.45151 26583.69935 0.48373 schema
3 0.00206 0.01292 0.02505 0.09679 116.93156 5337.36854 2.06006 truss
And the following gnuplot script:
set terminal png enhanced background rgb 'white' size 1920,1200 font "Verdana 10"
set output "charts/summary.png"
set boxwidth 0.2 absolute
set title "Validating all data"
set xrange[0:4]
set yrange[0.00005:50]
set logscale y
set grid y
set tics scale 0
set xtics rotate by -45
set xtics nomirror
set ytics nomirror
set border 2
set style fill solid 0.25 border -1
set style data boxplot
plot "data/summary" using 1:3:2:6:5:(0.6):xticlabels(9) with candlesticks title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4:(0.6) with candlesticks lt -1 notitle
The output of which looks like:
The problem being that I can't figure out how to set the background color of the boxes in the boxplot. I can only seem to turn on and off the fill-in color by removing the set style fill solid 0.25 border -1 line.
Although the name of keyword doesn't suggest so, the linecolor seems to affect the color of the boxes, thus for example:
plot "data/summary" using 1:3:2:6:5:(0.6):xticlabels(9) with candlesticks lc rgb 'blue' title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4:(0.6) with candlesticks lt -1 notitle
My data file has just two columns.The following MWE on those columns produces boxes with repeated colors. Is it possible to produce unique colors for each box?
reset
set term postscript eps size 5.5,4.5 enhanced color solid lw 2\
font "arial,28"
set key right
set xtics rotate -45 font ",20"
set style fill solid 1 border -1
plot 'rankdefcount.dat' using ($0):2:($0):xticlabels(1) \
notitle w boxes lc variable
quit
Here is the output I got:
After few attempts and help from the SO experts, I came up with the following solutions; none of them perfect, though.
Solution 1: ( with a random repetition using rand and rgb calls)
reset
set term postscript eps size 5.5,4.5 enhanced color solid lw 2 font \
"arial,28"
set key right
rgb(r,g,b)=int(255*r)*65536+int(255*g)*256+int(255*b)
do for [i=1:31] {
myrand=rand(int(rand(0)*i*100)+i*100)
set style line i linecolor rgb rgb(rand(0),rand(0),rand(0))
}
set xtics rotate -45 font ",20"
set style fill solid 1 border -1
plot 'rankdefcount.dat' using ($0):2:($0):xticlabels(1) \
notitle w boxes lc variable
quit
Here is the corresponding output:
With palette definition (solution 2):
reset
set term postscript eps size 5.5,4.5 enhanced color solid lw 2 font \
"arial,28"
set key right
set palette color model HSV
set palette defined (0 0 1 1,1 1 1 1)
set palette defined ( 0 0 1 0, 1 0 1 1, 6 0.8333 1 1, 7 0.8333 0 1)
set boxwidth 0.5
unset colorbox
set xtics rotate -45 font ",20"
set style fill solid 1 border -1
plot 'rankdefcount.dat' using ($0):2:($0):xticlabels(1) \
notitle w boxes lc palette
quit
This is the output:
For another solution (solution 3), replace the definition above with the following lines:
set palette color model HSV
set pm3d explicit at b
set palette rgbformulae 3, 2, 2
This is what I got:
You may try and redefine as much linetypes as boxes you want to show. The code should go before the plot.
colors="black red orange #fa8072 ...." #[as much colors as needed]
do for [L=1:words(colors)]{
set linetype L lc rgb word(colors,L)
}
You can find colors for gnuplot here.
http://www.uni-hamburg.de/Wiss/FB/15/Sustainability/schneider/gnuplot/colors.htm
I am executing the following gnuplot script:
set title "Efficiency scatter plot"
set xlabel "perf_1"
set ylabel "secondary report"
set log x
set log y
set xrange [0.1:40.0]
set yrange [0.1:40.0]
set terminal png medium
set output "./graph1.png"
set size square
set multiplot
set pointsize 0.3
set style line 6 pt 6
set datafile separator ","
set border 3
set xtics nomirror
set ytics nomirror
plot '/tmp/data.csv' using 3:1 with points pt 1 lt 3 lc var title "perf_20140113131309", \
'/tmp/data.csv' using 3:2 with points pt 1 lt 1 lc var title "perf_1"
plot x notitle
plot 2*x notitle
plot 0.5*x notitle
obtaining the following error message
"script.gnuplot", line 20: Not enough columns for variable color
Could you please guide me in order to find what I am doing wrong.
By the way the gnuplot version is '4.6 patchlevel 3' the data.csv files used is
0.1,0.1,40.0
0.14,0.14,40.0
0.32,0.32,40.0
0.7,0.74,40.0
Thanks in advance!
That means, that you need to specify one more column in your using statement: The first one is the x-coordinate, the second one the y-coordinate. The one for the variable line color is missing.
Use e.g.
plot '/tmp/data.csv' using 3:1:0 with points pt 1 lt 3 lc var
to use the row number (zeroth column) as linetype index. You can also use e.g. linecolor palette so select the color from the currently defined color palette.
is it possible to change the color of bars in a Gnuplot script dynamically?
I have the following script
reset
fontsize = 12
set term postscript enhanced eps fontsize
set output "bargraph_speedup.eps"
set style fill solid 1.00 border 0
set style histogram
set style data histogram
set xtics rotate by -45
set grid ytics linestyle 1
set xlabel "Benchmarks" font "bold"
set ylabel "Relative execution time vs. reference implementation" font "bold"
set datafile separator ","
plot 'bm_speedup.dat' using 2:xtic(1) ti "Speedup" linecolor rgb "#00FF00"
which generates this plot:
Is it possible to make the color of the bars which are below zero red?
Thanks,
Sven
You can mimic this behavior using the boxes style:
My test data:
zip 2
baz 2
bar -1
cat 4
foo -3
And then plotting with gnuplot:
set style line 1 lt 1 lc rgb "green"
set style line 2 lt 1 lc rgb "red"
set style fill solid
plot 'test.dat' u (column(0)):2:(0.5):($2>0?1:2):xtic(1) w boxes lc variable
# #xval:ydata:boxwidth:color_index:xtic_labels
You could split your data file into two parts, positive values and negative, and plot them separately:
plot 'bm_speedup_pos.dat' using 2:xtic(1) ti "Faster" linecolor rgb "#00FF00", \
'bm_speedup_neg.dat' using 2:xtic(1) ti "Slower" linecolor rgb "#FF0000"
Or, if you only need to generate a few graphs, a few times, a common technique is to generate the raw graph in gnuplot, then post-process it in an image editor to adjust the colors. If you go that route, I suggest having gnuplot generate the graph in SVG format, which will give you much better looking graphs than any of the bitmap formats.
Doesn't seem like histogram lets you do it. May be like this:
set boxwidth 0.3
f(v)=v<0?1:2
plot 'bm_speedup.dat' using 0:2:(f($2)):xticlabels(1) with boxes ti "Speedup" lc variable
Actually you can also use linecolor rgb variable and give the color like this:
plot 'bm_speedup.dat' using 2:xtic(1):($2 >= 0 ? 0x00FF00 : 0xFF0000) ti Speedup lc rgb variable