I am trying to color each individual box plot separately, but I am struggling to figure out how to modify my gnuplot script. Any help is appreciated! Here is my code:
set terminal pngcairo enhanced font 'Arial,12' size 800,800
set output 'quartiles_candlestick.png'
set style data boxplot
set key off # Remove the legend
# Set the color and outline style for boxplots
set style line 1 lc rgb "black" lt 1 lw 2 # Black outline with line type 1 and line width 2
set boxwidth 0.5 # Adjust the width of the boxes
set logscale y
# Set boxplot fill color
set style fill solid 0.5 border lc rgb "black" # Fill with blue and black borders
# Set custom x-axis labels
set xrange [0.5:5.5] # Adjust the range slightly to provide more space around the boxplots
plot 'output_statistics.txt' using 1:3:2:6:5:xticlabels(8) with candlesticks title 'Min-Max Whiskers' whiskerbars, \
'' using 1:4:4:4:4 with candlesticks lt -1 notitle
And here is the structure of my datafile
#x min Q1 median q3 max width label color
1 132.5 151.34 317.48 733.92 1314.00 582.57 ALC2 #440154
2 142.2 201.04 808.40 1485.33 2297.41 1284.29 ALC3 #31688E
3 2562.0 3073.71 4340.40 6080.67 6781.62 3006.96 ALC4 #1F9E89
4 121.3 166.85 400.00 778.06 2949.24 611.21 ALC5 #6CCE59
5 69.4 112.68 125.49 146.99 271.52 34.31 ALC6 #FDE725
I am hoping to generate a figure similar to this in terms of coloring:
In your data you define the colors via #abcdef
, however, #
is the default character for comments. So, you are basically commenting out your color. If you cannot or don't want to change your color definition in your input data, there is probably a way around it, but the easiest is probably to define your color as hex number, e.g. 0xabcdef
.
Another thing is that your data is spread over almost two orders of magnitudes. For the low values you would only see black borders but no box filled with color. Hence, you might want to set logscale y
.
If you check help candlesticks
, it is listed that you can add a column for color and use it via variable color, i.e. lc rgb var
.
Script:
### colored candlesticks plot
reset session
$Data <<EOD
#x min Q1 median Q3 max width label color
1 132.5 151.34 317.48 733.92 1314.00 582.57 ALC2 0x99759f
2 142.2 201.04 808.40 1485.33 2297.41 1284.29 ALC3 0x8eaabe
3 2562.0 3073.71 4340.40 6080.67 6781.62 3006.96 ALC4 0x85c7bc
4 121.3 166.85 400.00 778.06 2949.24 611.21 ALC5 0xace3a5
5 69.4 112.68 125.49 146.99 271.52 34.31 ALC6 0xfbf38e
EOD
set offsets 0.5,0.5,0,0
set boxwidth 0.4
set style fill solid 1.0 border lt -1
set logscale y
set yrange[50:10000]
set key noautotitle
plot $Data u 1:3:2:6:5:9:xticlabels(8) w candlesticks lc rgb var whiskerbars, \
'' u 1:4:4:4:4 w candlesticks lt -1 lc "grey" ti 'Min-Max Whiskers'
### end of script
Result: