Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #2012 > unrolled thread
| Started by | bryan <bryanlepore@gmail.com> |
|---|---|
| First post | 2013-09-01 11:22 -0700 |
| Last post | 2013-09-03 12:40 -0700 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.graphics.apps.gnuplot
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
| From | bryan <bryanlepore@gmail.com> |
|---|---|
| Date | 2013-09-01 11:22 -0700 |
| Subject | histogram bar colors |
| Message-ID | <d7c91259-2e16-470f-83fe-2cdce8ac1e0f@googlegroups.com> |
[ 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
#------------------------------------------------------------------------
[toc] | [next] | [standalone]
| From | sfeam <sfeam@users.sourceforge.net> |
|---|---|
| Date | 2013-09-01 16:46 -0700 |
| Message-ID | <l00jki$ba1$1@dont-email.me> |
| In reply to | #2012 |
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
[toc] | [prev] | [next] | [standalone]
| From | bryan <bryanlepore@gmail.com> |
|---|---|
| Date | 2013-09-01 19:31 -0700 |
| Message-ID | <167f9dc7-6782-47f9-bf5f-c3f17e1d85c5@googlegroups.com> |
| In reply to | #2013 |
On Sunday, September 1, 2013 7:46:22 PM UTC-4, sfeam wrote: > 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", thats interesting, and precisely what I was looking for - thanks a lot. also seems to be a good reason to get the latest patchlevel.
[toc] | [prev] | [next] | [standalone]
| From | sfeam <sfeam@users.sourceforge.net> |
|---|---|
| Date | 2013-09-03 12:40 -0700 |
| Message-ID | <l05e00$185$2@dont-email.me> |
| In reply to | #2014 |
bryan wrote:
> On Sunday, September 1, 2013 7:46:22 PM UTC-4, sfeam wrote:
>> 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",
>
> thats interesting, and precisely what I was looking for - thanks a lot.
> also seems to be a good reason to get the latest patchlevel.
Oops, I had forgotten that some versions had a bug in recognizing
the "fillcolor variable" keyword. Here is a slight variation that
should work also on older gnuplot versions starting from 4.4.
barcolor(n) = strstrt(strcol(n), "0") ? 0xff0000 : 0x0000ff
plot 'test_01sep13a.dat' u 0:3:(barcolor(1)):xticlabel(1) \
with boxes notitle lt rgb variable
The two colors in question are specified as 24-bit RGB colors
in hexadecimal form, pure red and pure blue in this case.
Ethan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.graphics.apps.gnuplot
csiph-web