|
From: Ethan A M. <eam...@gm...> - 2018-06-02 05:47:24
|
On Saturday, 02 June 2018 07:14:17 theozh wrote:
> 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.
My take is
set linetype 101 lc bgnd
set linetype 102 lc "seagreen"
set boxwidth 1.0
set yrange [0:*]
BIGNUM = 1.e5
plot $Data using ($1+0.5):(BIGNUM):($2==0?101:102) with boxes lc var noautoscale, \
whatever-the-foreground-plot-is
If ymin < 0 you would have to tweak this a bit.
Maybe draw the boxes twice, once with +BIGNUM once with -BIGNUM.
Or use boxxy, but that requires a more complicated using spec.
Ethan
>
> 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
>
>
> ------------------------------------------------------------------------------
> 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
|