The first coming idea is adding labels manually using command "set label ...". This a method but a poor efficient one. A better one is plot the labels with plot style "labels". And this is the method we will talk about here. A sample script is shown below.
reset set term png font "Times,18" #set terminal and output file set output "bar_labels.png" set xlabel "x value" #set x and y label set ylabel "Frequency" set xrange [-0.5:4.5] #set x and y range set yrange [0:4] set xtics 0,1,4 #set xtics set style fill solid #set plot style set boxwidth 0.5 unset key #legend not plotted plot "bar_data.dat" using 1:2 with boxes,\ "bar_data.dat" using 1:2:2 with labels #plot bar chart and the value labels on the bars
0 2 1 3 2 3 3 2 4 2
Run the script, we get picture file bar_labels.png like the following one.
Gnuplot bar chart with value labels |
If you do not like the position of the labels in the upper picture, you can just change it. For example,
lot "bar_data.dat" using 1:2 with boxes,\ "bar_data.dat" using 1:($2+0.25):2 with labels
Value labels with a 0.25 units higher position |
Hello, im new to gnuplot and have been following your post. I have this code, how do i add labels on top of the histogram like in this post ? can you explain a little about it ?
ReplyDeletereset
set term png font "Times,12"
set output "Recognition1.png"
set xlabel "Speaker"
set ylabel "Average Recognition Rate"
set yrange [0:100]
set xtic
set grid
set boxwidth 0.3 relative
set style fill transparent solid 1.0 noborder
plot 'C:\Users\tarmizi\Documents\gnuplot Document\WaveCeps.dat' using 2:xtic(1) with boxes lc rgb"blue" title "MFCC Recognition"
plot 'C:\Users\tarmizi\Documents\gnuplot Document\WaveCeps.dat' using 2:xtic(1) with boxes lc rgb"blue" title,\
Deleteplot 'C:\Users\tarmizi\Documents\gnuplot Document\WaveCeps.dat' using 2:xtic(1):xtic(1) with labels
You can refer to section "plotstyle labels" in the official document for some explanation.
Probably should be:
Deleteplot 'C:\Users\tarmizi\Documents\gnuplot Document\WaveCeps.dat' using 2:xtic(1) with boxes lc rgb"blue" title,\
plot 'C:\Users\tarmizi\Documents\gnuplot Document\WaveCeps.dat' using 0:2:2 with labels
xtic doesn't count as a data column, thus gnuplot will report that there is not enough data column for the "label" style plotting. Use "0" in place of the xtic.
Thank you very much for the reply... i'll try that :)
ReplyDeleteI am new to gnuplot. I have done couple of plots using the gnuplot. Your tutorial here has helped me a lot. But what do you mean by "Run the script, we get picture file bar_labels.png like the following one."
ReplyDeleteI am having troubles
nice
ReplyDelete:)
This was a really great contest and hopefully I can attend the next one. It was alot of fun and I really enjoyed myself.. labels
ReplyDelete