Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate box-and-whisker plots with variable box width, in gnuplot?

I'm trying to visualize a data set I have (in Java, but that doesn't matter much) using gnuplot. I could ask a few different questions about this, but for now: Suppose my data is categorical, and for each category I have quartiles 1,2,3, the min and max, and the total weight of samples in that category (but not the actual sample data). I want to plot this using GNUplot 'candlesticks'. I can almost get this:

the 'candlesticks' plot

except for visualizing the weight of samples using the box width.

Can this be done in a gnuplot 'candlesticks' plot? Some other way?

Note: I'm mostly interested in doing this with gnuplot. Other suggestions are welcome only if they're easily scriptable and do not require installing too much additional software.

like image 817
einpoklum Avatar asked Mar 14 '13 08:03

einpoklum


1 Answers

Ok, got it.

Sample script:

set terminal pngcairo  transparent enhanced font "arial,10" fontscale 1.0 size 500,    350 
set output 'candlesticks.png'
set boxwidth 0.2 absolute
set title "Box-and-whisker plot with median bar, whiskerbars, and variable box width" 
set xrange[0:5]
set yrange[0:25]

# Data columns: X Min 1stQuartile Median 3rdQuartile Max BoxWidth Titles

# set bars 4.0
set style fill empty
plot 'data.txt' using 1:3:2:6:5:7:xticlabels(8) with candlesticks title 'Quartiles' whiskerbars, \
  ''         using 1:4:4:4:4:7 with candlesticks lt -1 notitle

Sample Contents of data.txt:

# Data columns: X Min 1stQuartile Median 3rdQuartile Max BoxWidth Titles
1 5 7 10 15 24 0.3 Quick
2 6 8 11 16 23 0.4 Fox
3 5 7 11 17 22 0.5 Lazy
4 6 9 10 18 21 0.3 Dog

(and note that # lines are just comments, we don't really specify column names.)

The result:

Plot

like image 116
einpoklum Avatar answered Sep 28 '22 17:09

einpoklum