I am trying to do some histogram plots for an huge dataset with each
plot showing a section regarding different problems. There are around
100 keys and I can not print the complete keys within each plot. But
I want the colors of the keys unique within all the plots. So I have
to define the colors of each key otherwise the standard palette is
being used for every single plot with different keys.
I tried a lot changing colors around the following base testing script:
---
set terminal png transparent nocrop enhanced font arial 8 size 800,400
set output 'test.png'
set style data histograms
set style fill solid 1.0 border -1
set style histogram columnstacked
plot 'test.dat' using 2:key(1) ti col, \
'' using 3 ti col lt 4, \
'' using 4 ti col lt 3,\
'' using 5 ti col lt 5, \
'' using 6 ti col lt 5, \
'' using 7 ti col lt 5, \
'' using 8 ti col lt 5, \
'' using 9 ti col lt 5, \
'' using 10 ti col lt 5
---
Changing the colors in a "normal" Plot or within a histogram cluster
style plot is no problem by changing lt. But wihtin a histogram
columnstacked style these changes failed. Is there any possibility to
set the colors for fill style manually?
Thanks,
Wolfgang
I am not entirely sure that I understand what you want to do.
Here is one possibility, using syntax from the CVS version of gnuplot:
# Substitute a user-supplied sequence of line types
set style line 3 lt 4
set style line 4 lt 3
set style line 5 lt 5
set style line 6 lt 5
set style line 7 lt 5
set style line 8 lc rgb "gold"
...
set style increment user
# Use the same line type sequence for each histogram:
plot newhistogram lt 4, \
for [i=1:10] 'foo.dat' using i, \
newhistogram lt 4, \
for [i=1:10] 'baz.dat' using i
You can do the same thing in version 4.2.5, but you would have to expand
the for [i=1:10] in to 10 individual clauses.
Caveat: There was a recent bug fix to newhistogram that didn't quite make
it into 4.2.5. I am not sure whether it is relevant to your case or not.
Thank you, for your reply.
sfeam wrote:
> Wolfgang Schotte wrote:
> I am not entirely sure that I understand what you want to do.
Sorry, I'll try another explanation of what I want below.
> Here is one possibility, using syntax from the CVS version of gnuplot:
> # Substitute a user-supplied sequence of line types
> set style line 3 lt 4
[...]
> plot newhistogram lt 4, \
> for [i=1:10] 'foo.dat' using i, \
> newhistogram lt 4, \
> for [i=1:10] 'baz.dat' using i
I tried exactly this kind of line style before with an
set style histogram clustered
getting user defined colors within a clustered histogramm.
So far so good.
But I have to use a stacked histogram for some reasons
and defining colors within stacked histogram seems to
be done in another way?
My datafile looks like this but for more than 100 sample
types:
sample month1 month2 month3
sampleA 1 2 3
sampleB 4 3 2
sampleC 3 2 1
Now, needing a plot with only sample A and sample B I get:
^ #
| b sampleB (color b)
| b sampleA (color a)
| b b
| b a
| a a b
| a a b
| a a b
--------------------------
month1 month2 month3
Now, needing a plot with only sample B and sample C I get:
^ #
| sampleC (color b)
| sampleB (color a)
| b
| b b
| b a b
| a a a
| a a a
--------------------------
month1 month2 month3
You see, (color a) stands for sampleA in one plot and
for sampleB in the other one. But within the series of plots
I want the colors related to the sample types being unique,
for example in every plot sampleA should be represented
by (color a) even if it does not appear in a plot.
So, I can include all samples in every plot, but then
the list of keys would be half a textpage each diagram.
Then I thought, there are two possibilities:
1. Defining colors
I tried playing around with line style settings but this
brings no changes to clustered diagrams ... as far as I see.
2. Working with all keys but reducing the list of keys
to the relevant ones within the plot.
I did not find any option for that so far.
Or, perhaps I am totally wrong? I just didn't get it!?
Got any hints for me?
Thanks,
Wolfgang
Sorry, now I'm more confused than ever :-)
Your data column for month1 contains '1' for sample A and '4' for sample B.
But your ascii plot above contains 3 a's and 2 b's.
Similarly your plot has 4 a's and 3 b's for month2 rather than 2 and 3.
Are you sure you are plotting what you intended to plot?
Please clarify that first, and then I'll have a look at your other
requirements.
sfeam
Ups,... it's me, who has to say sorry. I did two sample data files
and a typo accidentally.
> Your data column for month1 contains '1' for sample A and '4' for
sample B.
> But your ascii plot above contains 3 a's and 2 b's.
> Similarly your plot has 4 a's and 3 b's for month2 rather than 2 and 3.
My datafile looks like this but for more than 100 sample types
(and this time it's a real copy-paste ;-):
sample month1 month2 month3
sampleA 3 4 1
sampleB 2 3 2
sampleC 1 1 3
these are the correct "plots":
Now, needing a plot with only sample A and sample B I get:
^ #
| b sampleB (color b)
| b sampleA (color a)
| b b
| b a
| a a b
| a a b
| a a a
--------------------------
month1 month2 month3
Now, needing a plot with only sample B and sample C I get:
^ #
| sampleC (color b)
| sampleB (color a)
| b
| b b
| b a b
| a a a
| a a a
--------------------------
month1 month2 month3
'(color a)' and 'a' represent red and
'(color b)' and 'b' represent green in a gnuplot output.
> Are you sure you are plotting what you intended to plot?
Now I am .... sorry again.
Thanks,
Wolfgang
PS: Minimal files to reproduce the first plot
test.dat
---
sample month1 month2 month3
sampleA 3 4 1
sampleB 2 3 2
#sampleC 1 1 3
---
test.gnu
---
set terminal png transparent nocrop enhanced font arial 8 size 800,400
set output 'test.png'
set style data histograms
set style fill solid 1.0 border -1
set xtics border in scale 1,0.5 nomirror offset character 0, 0, 0 \
rotate by -60
set style histogram columnstacked
plot 'test.dat' using 2:key(1) ti col, \
'' using 3 ti col, \
'' using 4 ti col
---
That should be the way it behaves by default.
There must be something else going on.
When you say "needing a plot with only sample A and sample B",
do you mean that all the other samples have value = 0?
Or did you use the "set datafile missing" command, or what?
> PS: Minimal files to reproduce the first plot
>
> test.dat
> ---
> sample month1 month2 month3
> sampleA 3 4 1
> sampleB 2 3 2
> #sampleC 1 1 3
Or is this showing that you commented out a bunch of lines?
If so, that's the problem.
If you want consistent colors by row number, then you must
not comment out any of the rows.
Instead try something like this (untested):
#Plot months 2 and 3 using only samples A and R
plot 'data' using ((strcol(1) eq "sampleA" || strcol(1) eq "sampleR") ? $3 : NaN), \
'' using ((strcol(1) eq "sampleA" || strcol(1) eq "sampleR") ? $4 : NaN)
Or maybe you need to put 0 rather than NaN; it may make a difference as to how
the key box is constructed.
If that more or less works, then we can maybe simplify the syntax a bit
by defining some helper functions.
sfeam schrieb:
>> '(color a)' and 'a' represent red and
>> '(color b)' and 'b' represent green in a gnuplot output.
> That should be the way it behaves by default.
Yes, that's what I get if I try the standard histogram.
> When you say "needing a plot with only sample A and sample B",
> do you mean that all the other samples have value = 0?
No, I have one large dataset with 129 samples across 36 month
and I want plots with only a few samples but different ones
each time across these 36 month to write something about the
comparison. And each sample should be plotted in the same
color in every plot.
> Or is this showing that you commented out a bunch of lines?
I did that, so the plots I did here, can be reproduced, sorry.
I try it another way, I have to find a workaround soon ... :-(
Using the following dataset and script:
t2.dat (yes, transposed this time ;-)
---
month sampleA sampleB sambleC
m1 3 4 1
m2 2 3 2
m3 1 1 3
---
t.gnu
---
set terminal png nocrop enhanced font arial 8 size 500,320
set output 't.png'
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set key outside right top vertical Left reverse enhanced autotitles
columnhead nobox
set key invert samplen 4 spacing 1 width 0 height 0
set style histogram rowstacked title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character
0, 0, 0
set yrange [0:10]
plot 't2.dat' using 2:xtic(1), '' using 3, '' using 4
---
I get:
^ #
|
| c sampleC (c = color blue)
| b c sampleB (b = color green)
| b c sampleA (a = color red)
| b b c
| b b c
| a b c
| a a b
| a a a
--------------------------
m1 m2 m3
I managed to change colors of line plots, histogram and
so one. But I did not manage changing the colors of
a stacked histogram so far.
For example, how do I change the color of samepleB from
green to yellow?
Thanks,
Wolfgang
> Hi!
>
> sfeam schrieb:
>>> '(color a)' and 'a' represent red and
>>> '(color b)' and 'b' represent green in a gnuplot output.
>> That should be the way it behaves by default.
>
> Yes, that's what I get if I try the standard histogram.
>
>> When you say "needing a plot with only sample A and sample B",
>> do you mean that all the other samples have value = 0?
>
> No, I have one large dataset with 129 samples across 36 month
> and I want plots with only a few samples but different ones
> each time across these 36 month to write something about the
> comparison. And each sample should be plotted in the same
> color in every plot.
>
>> Or is this showing that you commented out a bunch of lines?
>
> I did that, so the plots I did here, can be reproduced, sorry.
You must not comment out any of the lines. That won't work.
If you want consistent colors, every plot must use a file with
the same order of data lines.
Please use instead an explicit selection mechanism such as the
one I showed.
> |
> | c sampleC (c = color blue)
> | b c sampleB (b = color green)
> | b c sampleA (a = color red)
> | b b c
> | b b c
> | a b c
> | a a b
> | a a a
> --------------------------
> m1 m2 m3
>
> I managed to change colors of line plots, histogram and
> so one. But I did not manage changing the colors of
> a stacked histogram so far.
>
> For example, how do I change the color of samepleB from
> green to yellow?
set style increment user
set style line 2 lc rgb "yellow"
I know, that was foolish of me.
> If you want consistent colors, every plot must use a file with
> the same order of data lines.
> Please use instead an explicit selection mechanism such as the
> one I showed.
I am on it.
Thank you very much.
>> For example, how do I change the color of samepleB from
>> green to yellow?
> set style increment user
> set style line 2 lc rgb "yellow"
Huah? This works! ... I tried that already days ago?!?
Ok, where's the pillory?
By the way, is there any possibility to combine clustered
and stacked histograms? For example something that looks like
this:
^
| c
| b c
| b f c
| b e b f c
| b e b f c
| a d b e c f
| a d a d b e
| a d a d a d
--------------------------
m1 m2 m3
Thanks,
Wolfgang
>
> By the way, is there any possibility to combine clustered
> and stacked histograms? For example something that looks like
> this:
>
> ^
> | c
> | b c
> | b f c
> | b e b f c
> | b e b f c
> | a d b e c f
> | a d a d b e
> | a d a d a d
> --------------------------
> m1 m2 m3
Yes. You just need to start the second series at an appropriate
offset from the first series.
Here is an example using syntax from the cvs version (4.3):
set boxwidth 0.25
plot for [i in "6 12 13 14"] 'immigration.dat' using i ti col, \
newhistogram at .25, \
for [i in "7 12 15 16"] 'immigration.dat' using i ti col