|
From: theozh <th...@gm...> - 2018-06-02 21:18:35
|
Thank you Ethan,
ok, I haven't thought of boxes... probably the easiest workaround.
One way is certainly plotting boxes to +BIGNUM and -BIGNUM if you know for sure your data will be below this value.
The modified script below uses "replot" and GPVAL_Y_MAX and GPVAL_Y_MIN and works without BIGNUM. It also accounts for the fact that $Data column1 might also consist of other x-steps than 1.
However, when $Data column2 is 0="off" there is still be a hardly visible line at y=0. Actually, if I draw a box with height 0 I would expect to see absolutely nothing.
Well, this line you can avoid by changing the color to background using the ternary operator, as you did.
Thanks again, Theo.
PS.
minor detail still to fix: if $Data Col2 starts with 0, the key in the legend will have bgnd color (="invisible") instead of green color.
# local background depending on data
reset
$Data <<EOD
1 0
3 0
5 1
7 1
11 0
15 0
16 0
20 1
21 1
22 1
23 1
25 0
26 0
27 0
28 0
EOD
set colorsequence classic
do for [i=1:100] {
A = rand(0)*100
B = rand(0)*100
set linetype 101 lc bgnd
set linetype 102 lc "green"
set boxwidth 1.0 relative
plot \
$Data u 1:(A*sin($1)+B) w l lt 1
# reuse the GPVAL_Y_MAX and GPVAL_Y_MIN values
replot \
$Data u 1:(GPVAL_Y_MAX*$2):($2==0?101:102) w boxes lc var fs transparent solid 0.1 noborder t "shutter open" noautoscale, \
$Data u 1:(GPVAL_Y_MIN*$2):($2==0?101:102) w boxes lc var fs transparent solid 0.1 noborder notitle noautoscale, \
pause -1 "Press Enter to next plot"
}
# end gnuplot script
|