Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

See updated question below!:

(1 Old stuff) I have the following code:

unset key
# Make the x axis labels easier to read.
set xtics rotate out
# Select histogram data
set style data histogram
# Give the bars a plain fill pattern, and draw a solid line around them.
set style fill solid border

set title "Intensity of luxA signal for different substances"

set output 'luxA.png'
set terminal png transparent nocrop enhanced font times 18 size 840,640 

set ylabel "Intensität"

set style histogram

plot 'luxA.dat' using 2:xticlabels(1)

And the following data:

Name    Value   Color
"SN wt" 1103    blue
"SN ΔΔ" 124.3333333333  blue
"SN -A" 367.3333333333  blue
"SN -B" 147.3333333333  blue
"10nM C100" 325.6666666667  red
"200nM C100"    207.3333333333  red
"300nM C100"    236.6666666667  red
"LB"    180.6666666667  green
"LuxX"  168 green
"only LB"   62  green
"only MQ"   64.6666666667   green
"LB&wt" 65.3333333333   green
"SN LuxX&wt"    73  green

I want to color every bar according to the column "Color".

It also would be nice, if I could group the different groups a bit closer spatially (smaller distances within group and bigger between groups).

(2 New questions and data)

New data (fourth line for error bars (deviation)):

Name    Value   Color   Deviation
"SN wt" 1103    #006400 61.0
"SN ΔΔ" 124.3333333333  #006400 3.21
"SN -CI"    367.3333333333  #006400 25.38
"SN -B" 147.3333333333  #006400 20.74
"10nM C8"   325.6666666667  #0000FF 20.13
"200nM C8"  207.3333333333  #0000FF 28.7
"300nM C8"  236.6666666667  #0000FF 35.91
"1uM BDSF"  596.6666666667  #0000C6 44.12
"10uM BDSF" 545.3333333333  #0000C6 102.01
"15uM BDSF" 547 #0000C6 33.60
"1uM DSF"   596.3333333333  #00008B 98.47
"10uM DSF"  532 #00008B 21
"15uM DSF"  653.6666666667  #00008B 13.65
"LB"    180.6666666667  grey    20.13
"LuxA"  168 grey    20.07
"only LB"   62  grey    9.54
"only MQ"   64.6666666667   grey    20.03   
"LB \\& wt" 65.3333333333   grey    3.79
"SN Lux \\& wt" 73  grey    14.53

--> With this I want basically to achieve what I described above, but with error bars. The solution suggested below works for the colors, but not for the spacing on my computer (Ubuntu, gnuplot 4.4 patchlevel 2) And it is done with boxes? Is it possible to add error bars to boxes. I am a bit lost, I know C and Python but this gnuplot syntax scares my a bit... :-(

So I would like to have: - Bars according to color - Same groups (according color) grouped spatially together (small spacing in group, large spacing among groups) - Error bars according to column 4 (I do not care if it is done with boxes or with histogram, as long as it works :-| ) - The solution from mgilson (Thanks a lot!) for the spacing gives me an error (See below). What am I doing wrong? I use it exactly as stated...

By the way: What is your favourite gnuplot book out there?

share|improve this question

migrated from Nov 21 '12 at 9:32

This question came from our site for professional and enthusiast programmers.

up vote 0 down vote accepted

This can help get you started:

colors='red blue green'
set for [c in colors] style line strstrt(colors,c) lc rgb c
plot 'test.dat' u (column(0)):2:(strstrt(colors,stringcolumn(3))):xtic(1) w boxes lc variable

Note that I've done away with the histograms style. I like boxes better :).

Now for the spacing. This takes a little trickery with an inline function:

xidx(c)=(idx=idx+(c eq c_old?1.:1.5),cold=c,idx) #increment by 1 if same as old color, otherwise increment by 1.5
set for [c in colors] style line strstrt(colors,c) lc rgb c  #set linestyle for given color
plot 'test.dat' u (xidx(strcol(3))):2:(strstrt(colors,strcol(3))):xtic(1) w boxes lc variable
share|improve this answer
@Michael -- Sorry, copy/paste error in my second version. I tested it now and it seems to work with gnuplot 4.4.2 on OS-X using the x11 terminal. Hopefully that will work for you. – mgilson Nov 20 '12 at 21:42
@Michael -- the first version won't give you the spacing you want. The second version should give that to you...(It's just the first version with a little extra stuff tacked on to increase the space between boxes with different colors). – mgilson Nov 20 '12 at 21:46
OK, thanks! I just tested the color thing. But does the whole thing still produce error bars? I guess not??? – Michael Nov 20 '12 at 21:49
@Michael -- Error bars? What error bars? – mgilson Nov 20 '12 at 22:06
Ups, in this version I did not have introduced the error bars, sorry! Yeah, should also have error bars... – Michael Nov 20 '12 at 22:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.