-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot3d.gp
150 lines (94 loc) · 3.52 KB
/
plot3d.gp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# save as a cubehelix.gp
# run : gnuplot cubehelix.gp
# https://gitlab.com/adammajewski/color_gradient
# Set the output file type
set terminal png
# list of gradient names; update it maually
# gnuplot array is numbered from 1 to words(array), not like c arrays
# update list with order as in function GiveColor from p.c
titles = "Rainbow Linas Magma GrayL GrayNL2 GrayNL3 GraySqrt Green NewLinas CoolWarm GrayGamma GrayNL3Wave2 GrayNL3Wave10 GraySqrtWave ColorLWave ColorLWaveInverted NL3Wave5NonInv Cubehelix"
spaces = "RGB HSV"
# length of array spaces = nMax, but tex files are numbered from 0 to nMax-1 ( c style)
nMax = words(spaces)
# legend
set key inside bottom center horizontal
set key horizontal
set key font ",8"
# remove upper and right axis
set border 3 back
set xtics nomirror out
set ytics nomirror
set xlabel "gradient position"
set ylabel " intensity"
# adjust y range to make a space for the legend
set yrange [-0.2:1.1]
s=1
# plot nMax images
# https://stackoverflow.com/questions/14946530/loop-structure-inside-gnuplot
do for [n=0:nMax] {
print n
print 2
# Set the output file name
outfile = sprintf('%d.png',n)
set output outfile
# Set the intput file name
infile = sprintf('%d.txt',n)
# title of the image for the array of strings
sTitle = sprintf(" 2D %s profiles of the %s colormap", word(spaces,s), word(titles,n+1) )
set title sTitle
# Now plot the data with lines and points
plot infile using 1:2 with lines linecolor rgb 'red' title 'R', \
'' using 1:3 w lines linecolor rgb 'green' title 'G', \
'' using 1:4 w lines linecolor rgb 'blue' title 'B',\
'' using 1:5 w lines linecolor rgb 'black' title 'Y'
# 3d plot of rgb profile
print 3
set xlabel "R"
set ylabel "G"
set zlabel "B"
unset yrange
set nokey
unset tics
set xrange [0.0:1.0]
set yrange [0.0:1.0]
set zrange [0.0:1.0]
set grid
set border 4095 ls 1 lc rgb "black" # Draw a complete box around a `splot`:
set xzeroaxis
set yzeroaxis
# set view <rot_x>{,{<rot_z>}{,{<scale>}{,<scale_z>}}}
# view is 60 rot_x, 30 rot_z, 1 scale, 1 scale_z
rot_x = 60
rot_z = 75
set view rot_x,rot_z
set view equal xyz # to get an orthographic projection with all of the axes scaled equally
set xyplane at 0 # adjusts the position at which the xy plane is drawn in a 3D plot
# Set the output file name
outfile = sprintf('%d_3d_%d_%d_v.png',n, rot_x, rot_z)
set output outfile
# title of the image for the array of strings
sTitle = sprintf("3D %s profile of the %s colormap", word(spaces,s), word(titles,n+1) )
set title sTitle
# http://www.bersch.net/gnuplot-doc/linetypes,-colors,-and-styles.html
# There are several ways to specify color when one plots using gnuplot.
# Among them hex-string (like "#0000ff") and rgbvalue (like "256")
# specification is very important.
# here rgb value is computed
rgb(r,g,b) = 65536*int(255*r) + 256*int(255*g) + int(255*b)
# Now plot the data with lines and points
set label "(0,0,0)" at -0.1,0,0 right
#set label "0" at 1,-0.1,0 right
#set label "1" at 1,+1.1,0 right
#set label "2" at 0,1.1,0 right
#set label "3" at 0,1,1 left
#set label "4" at 0,0,1 left
# set label "5" at 1,0,1 left
#set label "6" at 1,0,0 left
set label "(1,1,1)" at 1.1,1,1 left
splot infile using 1:1:1 with lines lw 3 lc rgb 'gray',\
infile using 2:3:4:(rgb($2,$3,$4)) with points pt 7 ps 2 lc rgb variable ,\
'-' w p pt 7 ps 2 lc rgb 'black'
0 0 0
1 1 1
e
}