Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #2013

Re: histogram bar colors

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 <sfeam@users.sourceforge.net>
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 <l00jki$ba1$1@dont-email.me> (permalink)
References <d7c91259-2e16-470f-83fe-2cdce8ac1e0f@googlegroups.com>
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

Followups directed to: comp.graphics.apps.gnuplot

Show key headers only | View raw


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
   






Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

histogram bar colors bryan <bryanlepore@gmail.com> - 2013-09-01 11:22 -0700
  Re: histogram bar colors sfeam <sfeam@users.sourceforge.net> - 2013-09-01 16:46 -0700
    Re: histogram bar colors bryan <bryanlepore@gmail.com> - 2013-09-01 19:31 -0700
      Re: histogram bar colors sfeam <sfeam@users.sourceforge.net> - 2013-09-03 12:40 -0700

csiph-web