Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: sfeam Newsgroups: comp.graphics.apps.gnuplot Subject: Re: histogram bar colors Followup-To: comp.graphics.apps.gnuplot Date: Sun, 01 Sep 2013 16:46:22 -0700 Organization: gnuplot development team Lines: 88 Message-ID: References: Reply-To: sfeam@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Sun, 1 Sep 2013 23:46:26 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="e947cb29d2533e27aa00183e80187dbb"; logging-data="11585"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5zP5oFfQ8NywBzLqWJks9" User-Agent: KNode/4.4.9 Cancel-Lock: sha1:4l4U0zISivCezGUAT0RKoYROuwE= Xref: csiph.com comp.graphics.apps.gnuplot:2013 bryan wrote: > [ gnuplot 4.6 patchlevel 0 - yes I can upgrade this ASAP] > [ Ubuntu 12.04.3 LTS ] > [ misc downstream programs] > > I am wondering how to color particular bars a different color than a > default. my working script and data to plot fractions as a histogram > is copy/pasted below. AFAIK a rather general histogram setup is > employed. but specifically, the script uses: > > plot 'test_01sep13a.dat' u 3:xticlabel(1) > > to actually plot the data. > > in the example, there are two particular bars that should be at 500 > and 1000 in some alternate color. so the output plot would, for > example, have all the bars for the fruit (see data) in the color red, > and the bars for the numbers (500 and 1000) black. the idea is the > bars for the numbers would stand out. FYI this is to connect the > fractional value with the count ("how many") value. > > this script appears to be close to what I am looking for: > > http://gnuplot.sourceforge.net/demo/histograms.2.gnu > > but the data is plotted in a different way... I admit I could learn > more about the above syntax I am already using. > > here's the script and data: > ------------------------------------------------------- > set title "compare fruit categories" > set xtics 1 out > set grid > set key left top > unset label > set format y "%3.3f" > set xlabel "category" ; set ylabel "fraction " rotate by -90 > set style data histogram > set style fill solid border -1 > set style histogram > set xtics nomirror rotate by -90 > set ytics rotate by -90 > set bars back > plot 'test_01sep13a.dat' u 3:xticlabel(1) notitle > #------------------------------------------------------------------------ > #test_01sep13a.dat: > banana 53.08 0.000396244 > apple 160 0.00119441 > 500 500 0.00373252 > lemon 804.65 0.00600674 > tangerine 956.77 0.00714233 > kiwi 977.38 0.00729618 > 1000 1000 0.00746504 > starfruit 1022.31 0.00763158 > orange 1061.76 0.00792608 > #------------------------------------------------------------------------ You don't really need the "with histograms" style for this plot. It will be easier to show "with boxes". Add the following lines to your script: barcolor(n) = strstrt(strcol(n), "0") ? 2 : 3 set boxwidth 0.2 absolute and replace the plot command with plot 'test_01sep13a.dat' u 0:3:(barcolor(1)):xticlabel(1) \ with boxes fillcolor variable notitle The key point here is to specify "fillcolor variable", which says that the color will be determined based on the contents of some column in the input file. Since your data file does not have a column containing colors per se, I defined a coloring function that chooses either color 2 or color 3 based on whether the string in data column 1 contains the digit "0" or not. Much fancier coloring schemes are possible if you want to go to the trouble. Ethan