hendry
hendry

Reputation: 10813

Gnuplot multi column plot using CSV headings

gnuplot via a Jupyter Notebook

I'm struggling to get a multi-column bar chart / histogram going with my input as a CSV with headings. As well as the key showing the {wcfiles,wclines,clocfiles,cloclines} attributes.

$summary << EOD
browser,wcfiles,wclines,clocfiles,cloclines
webkitgtk-2.28.2,19472,4710385,18620,3120740
firefox-78.0.1,289298,43627834,240137,24371602
chromium-83.0.4103.116,420343,100340817,269434,49597826
EOD
set datafile separator ','
set yrange [0:*]      # start at zero, find max from the data
set style fill solid border -1
set ytics format "%.0s%c" #  will generate labels 100k 200k 300k ... 1M
set title 'sloc the Web'
plot '$summary' using 0:2:($0+1):xtic(1) with boxes lc variable,\
   "" u 3 title "wclines",\
   "" u 4 title "clocfiles"

Upvotes: 0

Views: 350

Answers (1)

theozh
theozh

Reputation: 25692

Check the examples @Ethan mentioned. In your case you should set logscale y, otherwise it will be difficult to visualize values with differences of several orders of magnitude.

Code:

### histogram clustered
reset session

$Data <<EOD
browser,wcfiles,wclines,clocfiles,cloclines
webkitgtk-2.28.2,19472,4710385,18620,3120740
firefox-78.0.1,289298,43627834,240137,24371602
chromium-83.0.4103.116,420343,100340817,269434,49597826
EOD

set datafile separator ','
set title 'sloc the Web'

set yrange [1000:*]
set logscale y
set ytics format "%.0s%c"

set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9

plot $Data u 2:xtic(1) ti col,\
     '' u 3 ti col,\
     '' u 4 ti col
### end of code

Result:

enter image description here

Upvotes: 1

Related Questions