Wednesday, August 31, 2011

Gnuplot advanced background color (0)

It is not so hard to plot a single color background graph using gnuplot, and we have done this in blog ---- simple background color. But how about a linear gradient colored background?

The fill color of a object can not be set to be gradient in gnuplot. So the method in simple background color can not be copied, at least can not be copied directly. But if we draw a set
of small rectangles with different color, it may have the same appearence as a large rectangle with linear gradient color. Now let us realize this idea.
reset
n=200   #number of rectangles
dx=1.0/n    #legth of rectangle
set palette defined(0"white",n"#ccffcc")  #set gradient color
set cbrange [0:n]
unset colorbox
set for [i=1:n] object i rectangle from screen (i-1)*dx,0 to \
screen i*dx+dx/2,1 fs solid 1.0 noborder fillcolor palette cb i \
behind
#draw a set of rectangle with diffrent color."+dx/2" makes the
#adjacent rectangles have a common part, so that the border is not
#so obvious
set term png
set output "backgradient1.png"
plot sin(x) w l lw 0 lc palette cb 0 notitle,sin(x) w l lw 2 lc \
rgb"blue" notitle
#The first plot is just used to enable the palette, and it will be
#covered by the second plot never appearing on the output picture.
set output
And the above commands produce the following graph:

Linear gradient colored background

No comments:

Post a Comment

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.