Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Gnuplot – bar plot with bar labels rotated 90 degrees clockwise

I have this Gnuplot script:

reset session

$Data <<EOD
"Push-Front"            2344 0x289e37
"Push-Back"             187  0x289e37
"Insert"                1222 0x289e37
"Push-Front-Collection" 519  0x289e37
"Push-Back-Collection"  420  0x289e37
"Insert-Collection"     287  0x289e37
"Search"                191  0x28579e
"Pop-Front"             4939 0xa83232
"Pop-Back"              251  0xa83232
"Delete"                4771 0xa83232
"Delete-Range"          345  0xa83232
EOD

set style line 11 lc rgb 0xeeeeee lt 1 lw 1
set style fill solid 1.0
set boxwidth 0.8
set key noautotitle
set ytics 1000
set grid y ls 11
set tics scale 0
set tics out
set xtics rotate by -45
set terminal svg size 450,300 enhanced font "Times New Roman,12"
set output '..\msc-sandbox\TotalDurationBarPlotArrayList.svg'
set yrange[0:5000]
set ylabel "Milliseconds"
plot $Data u 0:2:3:xtic(1) w boxes lc rgb var#, \
        '' u 1:2:3 w labels offset 0,0.7

It looks like this:

My bar plot

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I want to achieve, is to add bar height values on top of each bar, rotated clockwise by 90 degrees in order for the labels fit in the plot.

>Solution :

You don’t get your values on top

  1. because you end your line with w boxes lc rgb var#, \ where #, \ comments out the following line
  2. the plot command for the values should read u 0:2:2
  • You could also rotate your xticlabels by +45 or labels for the values by -90 degrees and align it right or left. That’s just a matter of personal reading preference.
  • add some offset/margin at the top to get the numbers above the value within the graph area.

Script:

### bar chart with rotated xticlabels and values on top
reset session

$Data <<EOD
"Push-Front"            2344 0x289e37
"Push-Back"             187  0x289e37
"Insert"                1222 0x289e37
"Push-Front-Collection" 519  0x289e37
"Push-Back-Collection"  420  0x289e37
"Insert-Collection"     287  0x289e37
"Search"                191  0x28579e
"Pop-Front"             4939 0xa83232
"Pop-Back"              251  0xa83232
"Delete"                4771 0xa83232
"Delete-Range"          345  0xa83232
EOD

set style line 11 lc rgb 0xeeeeee lt 1 lw 1
set style fill solid 1.0
set boxwidth 0.8
set key noautotitle
set ytics 1000
set grid y ls 11
set tics out
set xtics rotate by 45 right
set yrange[0:]
set ylabel "Milliseconds"
set offset 0,0, graph 0.1, 0

plot $Data u 0:2:3:xtic(1) w boxes lc rgb var, \
        '' u 0:2:2 w labels offset 0,0.5 rotate by 90 left
### end of script

Result:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading