Friday, September 9, 2011

Gradient colored curve in Gnuplot(2)

In the previous article we plot a gradient colored curve by expanding it to a 3-d surface and view the surface in a particular viewpoint. Today we talk about a third method.

In gnuplot we can specify the plotting colors by "rgbcolor variable". It can assign a separate color for each data point,line segment,or label based on additional information in the input data file. For example "plot 'data.dat' u 1:2:3 with points lc rgb variable" will plot each data point with separate color according to the third column of the data file. Now we come to plot the following data file using "rgbcolor variable".
0.0 	0.00 
0.2 	0.14 
0.4 	0.56 
0.6 	1.25 
0.8 	2.12 
1.0 	3.00 
1.2 	3.65 
1.4 	3.90 
1.6 	3.79 
1.8 	3.64 
2.0 	4.00 
2.2 	5.40 
2.4 	8.10 
2.6 	11.84 
2.8 	15.84 
3.0 	19.00 
3.2 	20.41 
3.4 	19.78 
3.6 	17.78 
3.8 	15.91 
4.0 	16.00 
4.2 	19.42 
4.4 	26.39 
4.6 	35.66 
4.8 	44.78 
5.0 	51.00 
5.2 	52.40 
5.4 	48.90 
5.6 	42.54 
5.8 	36.95 
6.0 	36.00 
6.2 	42.21 
6.4 	55.46 
6.6 	72.72 
6.8 	88.97 
7.0 	99.00 
7.2 	99.63 
7.4 	91.26 
7.6 	78.06 
7.8 	66.75 
8.0 	64.00 
8.2 	73.76 
8.4 	95.28 
8.6 	123.02 
8.8 	148.39 
9.0 	163.00 
9.2 	162.10 
9.4 	146.85 
9.6 	124.35 
9.8 	105.31 
Our plotting script is:
reset
plot "data.dat" #To get the max and min vaule
MAX=GPVAL_Y_MAX
MIN=GPVAL_Y_MIN
LEN=MAX-MIN
set term png
set output "gradient_colored_curve3.png"
set key off
plot "data.dat" w l lw 2 lc rgb"green" smooth csplines, \
     "data.dat" u 1:2:(255-($2-MIN)/LEN*255) w p pt 7 \
     ps 2 lc rgb variable notitle
#(255-($2-MIN)/LEN*255) means when data vary from min
#to max, color vary from blue to black
It is a simple and good method. But it is hard for us to design a beautiful color palette. This is its disadvantage.

At last is what does the picture gradient_colored_curve3.png looks like.

Gradient colored curve plotted by gnuplot

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.