On Friday, 12 July 2013, ColorIsSweet wrote:
> I'm making a bar histogram and I would like to draw each bar in a different
> color. Here's my data:
>
> Silver/Gray 1886923 29.963891005749588
> White 1265143 20.090171649127733
> Black 1258397 19.983046764474366
> Red 712602 11.315951238327779
> Blue 565317 8.9771002694319471
> Brown/Beige 203033 3.2241160251745069
> Yellow/Gold 186990 2.9693569791481238
> Green 171534 2.7239193543034079
> Other 47384 0.7524467142625525
>
> And here's my script
>
> set title "Histogram of machine color"
> set grid
> set yrange [0:35]
> set xrange [-.5:*]
> set style data histograms
> set style fill solid
> set xtics border in scale 0,10 nomirror rotate by -45
> plot "percent.out" using 3:xticlabels(1) notitle
>
> I know there's some magic in the universe somewhere that will let me color
> the histogram bars as gray, white, black, red, etc.. But what that magic
> is, is beyond me. Thanks in advance!
Here is a magic script, written in the idiom of gnuplot 4.7 so that the
data is in-line. You can trivially replace $DATA with the name of a data file.
$DATA << EOD
Gray 1886923 29.963891005749588
White 1265143 20.090171649127733
Black 1258397 19.983046764474366
Red 712602 11.315951238327779
Blue 565317 8.9771002694319471
Brown 203033 3.2241160251745069
Yellow 186990 2.9693569791481238
Green 171534 2.7239193543034079
Other 47384 0.7524467142625525
EOD
set style fill solid border -1
boxwidth = 0.5
color(name) = (name eq "Gray") ? 0xdddddd \
: (name eq "White") ? 0xffffff \
: (name eq "Black") ? 0x000000 \
: (name eq "Red") ? 0xff0000 \
: (name eq "Blue") ? 0x0000ff \
: (name eq "Green") ? 0x00ff00 \
: (name eq "Yellow") ? 0xffff00 \
: int(rand(0)*0xffffff)
plot $DATA using 0:3:(boxwidth):(color(strcol(1))):xtic(1) \
with boxes fillcolor rgb variable
Ethan
--
Tradition is not the worship of ashes, but the preservation of fire.
- Gustav Mahler
|