1

I have this data file (TotalDurationBarPlot.dat):

Indexed list 934
Tree list 3692
Array list 12274
Linked list 48188

What I wish to achieve is a histogram chart with 4 bars: one for Indexed list, one for Tree list, one for Array list, one for Linked list. My requirements are:

  1. Each bar has it's unique color,
  2. On top of each bar, there is a number denoting the height of the bar. (For example, above the Tree list, there is 3692.)
  3. It would be nice to have a legend on a light gray background with a thin black legend border at the top right corner.

My current attempt

As of now, my data file looks like:

# ILL TL AL LL
934 3692 12274 48188

... and my gnuplot script looks like:

set title font "Monospaced,13" 'Total duration'
set grid
set key right top
set style data histograms
set style histogram cluster gap 2
set style fill solid border 2
set xtics format ""
set grid ytics
set ylabel "Milliseconds"
set yrange [0:70000]
# set boxwidth 0.5 relative
# set label "Array list\n134908 ms" at graph 0.145,0.9

ArrayListColor   = "#491d75";
IndexedListColor = "#b32929";
LinkedListColor  = "#d49435";
TreeListColor    = "#12520b";

plot 'TotalDurationBarPlot.dat' using 1 title "Indexed list" linecolor rgb IndexedListColor, '' using 2 title "Tree list" linecolor rgb TreeListColor, '' using 3 title "Array list" linecolor rgb ArrayListColor, '' using 4 title "Linked list" linecolor rgb LinkedListColor, '' u 0:1:1 with labels offset -6.0,-100.0 title ""

set terminal png size 650,350 enhanced font "Monospaced,13"
set output 'TotalDuration.png'
replot
exit

It produces:

List comparison

PS

The linked question does not address my needs here. My requirements are:

  1. A legend box with (RGB) color for the legend border and background,
  2. The thickness of the legend border,
  3. The color of the bars,
  4. The y-value of each bar must be typeset above the respective bar,
  5. Minimum change in my current implementation.

(Finally, I cannot follow the code in the linked question.)

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
coderodde
  • 1,269
  • 4
  • 17
  • 34
  • You don't need histogram, you should use your original data and plot a simple bar chart (`with boxes`) and variable color. Plot the numbers as labels on top of the bar with some offset. Legend border is a different topic, please stay focused to _one_ topic. Just do a simple SO search with `[gnuplot] legend box background`. – theozh May 24 '23 at 07:38

0 Answers0