|
From: theozh <th...@gm...> - 2017-10-27 21:25:13
|
Hi,
Is there maybe a simple way to place the values on top of
in a column stacked histogram?
The following example does not place the labels at the right
y-positions, i.e. ideally centered within the different portions.
For this you would need to somehow sum up the previous values. I do not
see how...
Any hints are appreciated!
Theo.
###### gnuplot code start
reset
$Data <<EOD
XXX Header1 Header2
one 10 50
two 20 30
three 30 15
four 40 5
EOD
set style data histogram
set style histogram columnstacked
set style fill solid border -1
set boxwidth 0.75
plot $Data u 2 ti col , '' u 3:key(1) ti col, \
'' u (0):2:2 with labels notitle, '' u (1):3:2 with labels notitle
###### gnuplot code end
|
|
From: Ethan M. <eam...@gm...> - 2017-10-27 22:50:58
|
This could maybe serve as a starting point. The placement is not pretty
but it shows the basic principle.
plot $Data u 2 ti col , '' u 3:key(1) ti col, \
ysum=0 '' skip 1 using (0):((ysum = ysum + $2, ysum-5)):2 with labels
notitle, \
ysum=0 '' skip 1 using (1):((ysum = ysum + $3, ysum-5)):3 with labels
notitle
On Fri, Oct 27, 2017 at 2:24 PM, theozh <th...@gm...> wrote:
> Hi,
> Is there maybe a simple way to place the values on top of
> in a column stacked histogram?
> The following example does not place the labels at the right
> y-positions, i.e. ideally centered within the different portions.
> For this you would need to somehow sum up the previous values. I do not
> see how...
> Any hints are appreciated!
> Theo.
>
> ###### gnuplot code start
> reset
> $Data <<EOD
> XXX Header1 Header2
> one 10 50
> two 20 30
> three 30 15
> four 40 5
> EOD
>
> set style data histogram
> set style histogram columnstacked
> set style fill solid border -1
> set boxwidth 0.75
>
> plot $Data u 2 ti col , '' u 3:key(1) ti col, \
> '' u (0):2:2 with labels notitle, '' u (1):3:2 with labels notitle
>
> ###### gnuplot code end
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> gnuplot-info mailing list
> gnu...@li...
> Membership management via: https://lists.sourceforge.net/
> lists/listinfo/gnuplot-info
>
|
|
From: theozh <th...@gm...> - 2017-10-28 08:24:05
|
Thanks a lot Ethan,
I'll never would have found this one.
With the minor change "ysum-$2/2", the following seems to place the
number in the center of the portion.
plot $Data u 2 ti col , '' u 3:key(1) ti col, \
ysum=0 '' skip 1 using (0):((ysum = ysum + $2, ysum-$2/2)):2 with
labels notitle, \
ysum=0 '' skip 1 using (1):((ysum = ysum + $3, ysum-$3/2)):3 with
labels notitle
However, if looking at the syntax in "help plot"
plot-element:
{<iteration>}
<definition> | {sampling-range} <function> | <data source>
{axes <axes>} {<title-spec>}
{with <style>}
I still don't understand why and how ((ysum = ysum + $2, ysum-$2/2))
works. So apparently, you can place an expression/function before the
comma and the expression after the comma is actually plotted? Good to
know, I didn't know that one can make such constructs. Would be nice to
have an example in "plot help" or if you have a link where to find this
documented, please let me know.
|
|
From: sfeam <sf...@us...> - 2017-10-28 16:31:18
|
On Saturday, 28 October 2017 10:23:40 theozh wrote:
> Thanks a lot Ethan,
> I'll never would have found this one.
> With the minor change "ysum-$2/2", the following seems to place the
> number in the center of the portion.
>
> plot $Data u 2 ti col , '' u 3:key(1) ti col, \
> ysum=0 '' skip 1 using (0):((ysum = ysum + $2, ysum-$2/2)):2 with
> labels notitle, \
> ysum=0 '' skip 1 using (1):((ysum = ysum + $3, ysum-$3/2)):3 with
> labels notitle
>
> However, if looking at the syntax in "help plot"
> plot-element:
> {<iteration>}
> <definition> | {sampling-range} <function> | <data source>
> {axes <axes>} {<title-spec>}
> {with <style>}
>
> I still don't understand why and how ((ysum = ysum + $2, ysum-$2/2))
> works.
The comma is a mathematical binary operator indicating
serial evaluation. The operation
A,B
signifies "first evaluate A, then evaluate B, return the latter result"
https://en.wikipedia.org/wiki/Comma_operator
> So apparently, you can place an expression/function before the
> comma and the expression after the comma is actually plotted? Good to
> know, I didn't know that one can make such constructs. Would be nice to
> have an example in "plot help" or if you have a link where to find this
> documented, please let me know.
gnuplot> help expression operators binary
(4th from last in the long list of operators)
Serial evaluation occurs only in parentheses and is guaranteed to proceed
in left to right order. The value of the rightmost subexpression is returned.
For a demo the makes good use of this operator see
http://gnuplot.sourceforge.net/demo_cvs/running_avg.html
Ethan
|
|
From: theozh <th...@gm...> - 2017-10-28 23:01:12
|
Thank you again, Ethan, for the explanations and links. What's still not clear to me why you can place the ysum=0 between two plot commands... What else can you place in front of a plot command? For example: n=1 plot n=n+1 sin(x*n) # works plot (n=1,n=n+1) sin(x*n) # doesn't work... why? Anyway, my original question is solved :-). Nevertheless, I played around a little further. If the portions in the stacked histogram are too small to fit a number, the following code shows a way to place those numbers on the side with a pointing arrow. Maybe some people also mind find this useful. The following code was working on my system (Win7, gnuplot 5.2) and should be ready for copy&paste&plot. Be aware that the mail program might have "messed up" the line breaks. ###### start gnuplot code reset $Data <<EOD XXX Header1 Header2 one 10 50 two 3 2 three 30 15 four 40 5 five 0.5 0.5 six 0.6 0.6 seven 1 17 EOD set style data histogram set style histogram columnstacked set style fill solid border -1 set boxwidth 0.6 YminSpace = 4 YStep = 2 YExtraDistance = -YStep XShift(n) = (n < YminSpace) ? 0.45 : 0 YShift(n) = (n < YminSpace) ? (YExtraDistance=YExtraDistance+YStep,YExtraDistance) : (YExtraDistance=-YStep,0) plot \ $Data u 2 ti col , '' u 3:key(1) ti col, \ ysum=0 '' skip 1 using (0+XShift($2)):((ysum = ysum + $2, ysum-$2/2+YShift($2))):2 with labels notitle, \ ysum=0 '' skip 1 using (1+XShift($3)):((ysum = ysum + $3, ysum-$3/2+YShift($3))):3 with labels notitle,\ ysum=0 '' skip 1 using ($2>YminSpace ? 1/0:(0+XShift($2)-0.05)):((ysum = ysum + $2, ysum-$2/2+YShift($2))):(-0.1):(-YExtraDistance) ls -1 with vectors not,\ ysum=0 '' skip 1 using ($3>YminSpace ? 1/0:(1+XShift($3)-0.05)):((ysum = ysum + $3, ysum-$3/2+YShift($3))):(-0.1):(-YExtraDistance) ls -1 with vectors not,\ ###### end gnuplot code |
|
From: sfeam <sf...@us...> - 2017-10-29 22:36:14
|
On Sunday, 29 October 2017 01:01:10 theozh wrote:
> Thank you again, Ethan, for the explanations and links.
>
> What's still not clear to me why you can place the
> ysum=0 between two plot commands...
That part is explained by "help plot".
Syntax:
plot {<ranges>} <plot-element> {, <plot-element>, <plot-element>}
Each plot element consists of a definition, a function, or a data source
together with optional properties or modifiers:
plot-element:
{<iteration>}
<definition> | {sampling-range} <function> | <data source>
{axes <axes>} {<title-spec>}
{with <style>}
the "ysum = 0" matches the <definition> template "foo = <expression>".
> What else can you place in front of a plot command?
> For example:
> n=1
> plot n=n+1 sin(x*n) # works
> plot (n=1,n=n+1) sin(x*n) # doesn't work... why?
because "(n=1,n=n+1)" is not a definition.
You could make it one by adding a dummy assignment:
plot dummy=(n=1,n=n+1) sin(x*n)
Ethan
>
> Anyway, my original question is solved :-).
> Nevertheless, I played around a little further.
> If the portions in the stacked histogram are too small to fit a number,
> the following code shows a way to place those numbers on the side with a
> pointing arrow.
> Maybe some people also mind find this useful.
>
> The following code was working on my system (Win7, gnuplot 5.2) and
> should be ready for copy&paste&plot. Be aware that the mail program
> might have "messed up" the line breaks.
>
> ###### start gnuplot code
> reset
> $Data <<EOD
> XXX Header1 Header2
> one 10 50
> two 3 2
> three 30 15
> four 40 5
> five 0.5 0.5
> six 0.6 0.6
> seven 1 17
> EOD
>
> set style data histogram
> set style histogram columnstacked
> set style fill solid border -1
> set boxwidth 0.6
>
> YminSpace = 4
> YStep = 2
> YExtraDistance = -YStep
> XShift(n) = (n < YminSpace) ? 0.45 : 0
> YShift(n) = (n < YminSpace) ?
> (YExtraDistance=YExtraDistance+YStep,YExtraDistance) :
> (YExtraDistance=-YStep,0)
>
> plot \
> $Data u 2 ti col , '' u 3:key(1) ti col, \
> ysum=0 '' skip 1 using (0+XShift($2)):((ysum = ysum + $2,
> ysum-$2/2+YShift($2))):2 with labels notitle, \
> ysum=0 '' skip 1 using (1+XShift($3)):((ysum = ysum + $3,
> ysum-$3/2+YShift($3))):3 with labels notitle,\
> ysum=0 '' skip 1 using ($2>YminSpace ? 1/0:(0+XShift($2)-0.05)):((ysum
> = ysum + $2, ysum-$2/2+YShift($2))):(-0.1):(-YExtraDistance) ls -1 with
> vectors not,\
> ysum=0 '' skip 1 using ($3>YminSpace ? 1/0:(1+XShift($3)-0.05)):((ysum
> = ysum + $3, ysum-$3/2+YShift($3))):(-0.1):(-YExtraDistance) ls -1 with
> vectors not,\
>
> ###### end gnuplot code
|
|
From: theozh <th...@gm...> - 2017-10-29 23:18:39
|
Thanks again for your patient explanations.
My (mis)understanding probably is that I thought you can place
either (i.e. XOR) a <definition> or a <function> or a <data source>
plot-element:
{<iteration>}
<definition> | {sampling-range} <function> | <data source>
{axes <axes>} {<title-spec>}
{with <style>}
however,
plot n=n+1 sin(x*n)
is a <definition> AND a <function>
whereas <function> AND <data source> at the same time is not supposed to work.
|
|
From: sfeam <sf...@us...> - 2017-10-29 23:42:51
|
On Monday, 30 October 2017 00:18:31 theozh wrote:
> Thanks again for your patient explanations.
>
> My (mis)understanding probably is that I thought you can place
> either (i.e. XOR) a <definition> or a <function> or a <data source>
>
> plot-element:
> {<iteration>}
> <definition> | {sampling-range} <function> | <data source>
> {axes <axes>} {<title-spec>}
> {with <style>}
Your have a point.
The BNF syntax shown in the help text is not correct.
Probably it has been amended in parallel to changes in the plot code
and at some point the logic diverged.
I should probably go back to the source and work out a proper description
from the ground up.
Ethan
> however,
> plot n=n+1 sin(x*n)
> is a <definition> AND a <function>
> whereas <function> AND <data source> at the same time is not supposed to work.
|