|
From: theozh <th...@gm...> - 2018-06-02 05:14:28
|
Hello,
I am trying to create a plot with background color depending on a datafile. The datafile basically just contains 0s and 1s for "off" and "on". When it is "on" the background should be e.g. a light green and should span the whole y-range of the plot.
I tried with fillstep and calculate the ymin and ymax using the 0s and 1s from the data file and GPVAL_Y_MIN and GPVAL_Y_MAX. That's why I apparently have to use "replot" to get the actual (autoscaled) values.
The script below seem to work in general but for some strange reason not always. Sometimes the GPVAL_Y_MIN and GPVAL_Y_MAX values do not correspond to the y-axis minimum and maximum.
Furthermore, the fillstep fills always to 0, not from ymin to ymax.
Maybe I am just thinking too complicated and there is a function to do this much simpler?
Any ideas? Thank you.
I put the following script into a loop so that you can try several times and see that it sometimes works sometimes not...
# gnuplot script: local background depending on data
reset
$Data <<EOD
1 0
2 0
3 1
4 1
5 0
6 0
7 0
8 1
9 1
10 1
11 1
12 0
13 0
14 0
15 0
EOD
set colorsequence classic
do for [i=1:100] {
A = rand(0)*100
B = rand(0)*100
plot A*sin(x) + B
set label 1 sprintf("A: %g\nB: %g\nGPVAL_Y_MIN: %g\nGPVAL_Y_MAX: %g",A,B,GPVAL_Y_MIN,GPVAL_Y_MAX) at screen 0.5,0.5 noenhanced
replot $Data u 1:((GPVAL_Y_MAX - GPVAL_Y_MIN)*$2 + GPVAL_Y_MIN) w fillsteps fs transparent solid 0.1
pause -1 "Press Enter to next plot"
}
# end gnuplot script
|