So, here is my data file
1 3 4 2 3 5 2which I will just name as 'bar.dat', and here is our script
reset unset key set style fill solid 1.0 set yrange [0:6] colour = "#080000" f(x,n) = (colour = sprintf("#%02X%02X%02X", 128+n/2, n, n), x) w(n) = 0.8*cos(n/230.0*pi/2.0) plot for [n=1:230:2] 'bar.dat' u 0:(f($1,n)):(w(n)) with boxes lc rgbcolor colourSimple enough, let us see what it does! The first four lines are just the usual settings, although, the yrange is really irrelevant. I set it only for aesthetic reasons (otherwise, gnuplot would set the yrange automatically to [1:5] for the data file above, and we wouldn't see one of the columns). Then we define a variable called 'colour'm which we will eventually overwrite in our function definition of f(x,n). f(x,n) returns x, thus, in this regard it would be absolutely useless, but when doing so, it actually prints a string to 'colour'. The next function is w(n), which will determine in what fashion our colour will converge to white.
Finally, we plot the data file some 115 times, each time with a smaller, and shinier box. At the end, we get something like this
We can very easily change the direction of the light. All we have to do is define a new function that shifts the bars as we progress with our for loop. So, the new script could be something like this
reset unset key set style fill solid 1.0 set yrange [0:6] colour = "#080000" f(x,n) = (colour = sprintf("#%02X%02X%02X", 128+n/2, n, n), x) w(n) = 0.8*cos(n/230.0*pi/2.0) shift(x,n) = x-0.8*n/850.0 plot for [n=1:230:2] 'bar.dat' u (shift($0,n)):(f($1,n)):(w(n)) with boxes lc rgbcolor colourwith a result as in this graph
Cheers,
Zoltán
This is not an error per se. The problem is that you are not using gnuplot 4.4, but some earlier version. I forgot to explicitly point out in this post that you need 4.4 in order to run this script. Both the function declaration and the for loop are new, and will not work on 4.2.
ReplyDeleteCheers,
Zoltán