Showing posts with label shadow. Show all posts
Showing posts with label shadow. Show all posts

Sunday, September 4, 2011

Shadow to the key in Gnuplot

Yesterday we talk about shadow to a curve in gnuplot . But the key is not plotted. Now we come to add a shadowed key to our graph. The method is the same as before, plotting the objects two or more times. The following is an example gnuplot script.
reset
set term png
set output "shadowkey.png"
dy=0.75
angle=pi/6.0
dx=dy*tan(angle)
f(x)=0.1*(x-10)*x*(x+10)
set object 1 rectangle from graph 0.91,0.89 \
    to graph 0.66,0.74 fillstyle solid 1.0 noborder \
    fc rgb"#cccccc"	#key-box shadow
set object 2 rectangle from graph 0.9,0.9 \
    to graph 0.65,0.75 fc rgb"#ffffff"    #key-box
set arrow 1 lw 7 lc rgb"#cccccc" from graph 0.78,0.82 \
    to graph 0.86,0.82 nohead #samle-line shadow
set arrow 2 lw 7 lc rgb"red" from graph 0.77,0.83 \
    to graph 0.85,0.83 nohead     #sample-line
set label 1 "f(x)" at graph 0.7,0.83	#key label
set xrange [-15:15]
plot f(x-dx)-dy w l lw 7 lc rgb"#cccccc" notitle,\
     f(x) w l lw 7 lc rgb"red" notitle
Because gnuplot can not give us enough control on the key by using command "set key ...", in this script we draw the key manually using rectangles,arrows and label. The final appearance of shadow1.png is shown below.

Shadow to the key in gnuplot

Saturday, September 3, 2011

Shadow to a curve in Gnuplot

Adding shadow to a curve or some other objects can makes a 2-d plot looks like a 3-d one. The common way producing a shadow effect is drawing the object two times. Now let us come to an example of shadowing to a curve.
reset
set term png
set output "shadow1.png"
dy=0.75
dx=dy*tan(pi/6)
f(x)=0.1*(x-10)*x*(x+10)
set xrange [-15:15]
plot f(x-dx)-dy w l lw 7 lc rgb"#cccccc" notitle,\
      f(x) w l lw 7 lc rgb"red" notitle
Simple shadow effect
Firstly the shadow offset along y-axis and x-axis are given. The earlier plot is used to produce the shadow effcet and the later one is the data plotting. Note that the data plotting must be put after the shadow plotting, otherwise the "shadow" may cloud the data-curve. From the picture we find that the shadow effect have been realized, but it seems that the shadow is too sharp. We need to improve the script to get a better effect. Now let us do this. Our main idea is plotting the shadow sevral times with diffrent scale of gray colors. We realize this idea using a "for" iteration. The following is our improved script and the corresponding graph.
reset
set term png
set output "shadow2.png"
dy=0.75
dx=dy*tan(pi/6)
levels=15
f(x)=0.1*(x-10)*x*(x+10)
set palette gray
set cbrange [0:1]
unset colorbox
set xrange [-15:15]
set yrange [-200:200]
set multiplot
plot for [i=levels:1:-1] f(x-i*(1.0/levels)*dx)-i*(1.0/levels)*dy w l lw 7 \
      lc palette cb i*(0.5/levels)+0.35 notitle
plot f(x) w l lw 7 lc rgb"red" notitle
unset multiplot
Improved shadow effect
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.