-bryan
# gnuplot script :
reset ; set border 9 ; set ytics nomirror ; \
set xrange [0:5] ; set yrange [0:0.5] ; set y2range [0:0.5]; \
set y2tics 0.1 nomirror rotate by 90 ; unset ytics ; \
set style histogram clustered gap 1 ; set y2label "Juiciness" ; \
set label "Label 1" at "< grep Banana data_1.dat | awk '{print $1
"," ($2+0.1)}'" textcolor lt -1 rotate by 90 ; \
set label "Label 2" at "< grep Apple data_1.dat | awk '{print $1
"," ($2+0.1)}'" textcolor lt -1 rotate by 90 ; \
set label "Label 3" at "< grep Kiwi data_1.dat | awk '{print $1
"," ($2+0.1)}'" textcolor lt -1 rotate by 90 ; \
set label "Label 4" at "< grep Orange data_1.dat | awk '{print $1
"," ($2+0.1)}'" textcolor lt -1 rotate by 90 ; \
set style fill solid border -1 ; set xtics offset 0,-2.5 nomirror
rotate by 90 ;
plot \
for [i=0:1] 'data_1.dat' u 1:2:3:xticlabel(4) every ::i w boxerror
notitle lw 2 lc 1, \
for [i=2:3] 'data_1.dat' u 1:2:3:xticlabel(4) every ::i w boxerror
notitle lw 2 lc 1
# data :
1 0.2938 0.0664 "Banana"
2 0.1184 0.0346 "Apple"
3 0.1938 0.0464 "Kiwi"
4 0.2184 0.0546 "Orange"
Use the 'labels' style (help labels). For example, amend your plot
command with
for [i=1:4] '' u 1:($2+0.1):("Label ".i) every ::i w labels
Péter Juhász
nice! i did this :
for [i=0:3] '' u 1:($2+0.1):5:xticlabel(5) every ::i w labels notitle
lw 2 lc -1
... it doesn't look like the labels can be rotated that way - is that
right?
-bryan
They can be rotated alright! Use the 'rotate' keyword, just as you
would with "set label".
The order of keywords is not completely free, certain combinations may
give an error message.
Look up the syntax of "set label", the order described there is
guaranteed to work.
By the way, 'lw 2 lc -1' does not do what you think it does. 'lw 2' is
meaningless, use 'font ",fontsize"', where fontsize is a number, if
you want to control font size. And write 'tc lt -1' instead of 'lc -1'
- perhaps their full form 'textcolor' instead of 'linecolor' is more
intuitive.
So, putting it together:
plot for [i=0:3] '' u 1:($2+0.1):5:xticlabel(5) every ::i w labels
rotate by 90 tc lt -1 notitle
A tip to set font sizes: declare a variable, like 'fs = 10'. Use that
when you set up your terminal:
set term whatever font "fontname,".fs
Then use
font ",".(fs*2)
in your plot command to get labels that are twice as big as the tick
markings, axis labels etc. This way, if you change your terminal, or
your plot size, you can just set fs to the desired value, and the
labels created by 'plot' will scale accordingly.
Péter Juhász
this would be brillant except that all the xticlabels are lost (see
new data file) - is this an impossible 'conflict'?:
for [i=0:1] 'data_1.dat' u 1:2:3:xticlabel(4) every ::i w boxerror
notitle lw 2 lc 1,
for [i=2:2] '' u 1:2 every ::i notitle lc -1 ps 0 lw 0,
for [i=3:4] '' u 1:2:3:xticlabel(4) every ::i w boxerror notitle lw 2
lc 2,
for [i=0:4] '' u 1:($2+0.1):5:xticlabel(5) every ::i w labels notitle
lw 2 tc lt -1 rotate by 90
new data file :
1 0.2938 0.0664 "Banana" ++
2 0.1184 0.0346 "Apple" +/-
3 0 0 "" .
4 0.1938 0.0464 "Kiwi" -
5 0.2184 0.0546 "Orange" +++
reset ; set border 9 ; set ytics nomirror ; set xtics scale 0
nomirror ;
max=0.5 ; fs=18 ; unset ytics ; set boxwidth 0.5 ;
set xrange [0:6] ; set yrange [0:max] ; set y2range [0:max];
set y2tics 0.1 nomirror rotate by 90 ; set bars back ;
set style histogram clustered gap 1 title offset 2,0.25 ; set y2label
"Juiciness" ;
set style fill solid border -1 ; set xtics offset 0,-2.5 nomirror
rotate by 90 ;
plot
for [i=0:4] 'data_1.dat' u 1:($2+0.1):5:xticlabel(5) every ::i w
labels notitle lw 2 tc lt -1 rotate by 90,
for [i=0:1] '' u 1:2:3:xticlabel(4) every ::i w boxerror fill empty
notitle lw 2 lc -1,
for [i=3:4] '' u 1:2:3:xticlabel(4) every ::i w boxerror fill empty
notitle lw 2 lc -1,
for [i=0:1] '' u 1:2 every ::i w boxes notitle lc 1,
for [i=2:2] '' u 1:2 every ::i notitle lc -1 ps 0 lw 0,
for [i=3:4] '' u 1:2 every ::i w boxes notitle lc 2
data_1.dat :
1 0.2938 0.0664 "Banana" ++
2 0.1184 0.0346 "Apple" +/-
3 0 0 ""
4 0.1938 0.0464 "Kiwi" -
5 0.2184 0.0546 "Orange" +++
... still working on the font tip
-bryan
Cleaned up version:
reset ; set border 9 ;
set ytics nomirror ; set xtics scale 0 nomirror ;
max=0.5 ; fs=18 ; factor = 1
# include these for your final, "production" version
# and then change factor
#set term whatever font ",".fs
#set output "whatever"
unset ytics ; set boxwidth 0.5 ;
set xrange [0:6] ; set yrange [0:max] ; set y2range [0:max];
set y2tics 0.1 nomirror rotate by 90 ; set bars back ;
set style histogram clustered gap 1 title offset 2,0.25 ;
set y2label "Juiciness" ;
set style fill solid border -1 ;
set xtics offset 0,-2.5 nomirror rotate by 90 ;
unset key
plot \
'data_1.dat' u 1:($2+0.1):5 w labels tc lt -1 \
rotate by 90 font sprintf(",%f",fs*factor),\
'' u 1:2:2:($2+$3):xticlabel(4) every ::0::1 w yerror lw 2 lc -1 ps
0,\
'' u 1:2:2:($2+$3):xticlabel(4) every ::3::4 w yerror lw 2 lc -1 ps
0,\
'' u 1:2:($1>2?2:1) w boxes lc var lw 2