[英]How to plot a contour with variable line color in Gnuplot?
我想 plot 具有可变线条颜色的单个轮廓。 我在数据文件中明确定义了每个 (x,y) 点的颜色,如下所示
-0.4000 -0.4000 7.6807 253 0 0
-0.3933 -0.4000 7.6907 253 10 0
-0.3867 -0.4000 7.7009 153 25 45
-0.3800 -0.4000 7.7112 33 25 90
-0.3733 -0.4000 7.7215 200 130 40
-0.3667 -0.4000 7.7320 23 11 100
.
.
.
上面,前三列对应于 x、y 和 z 值,后三列分别是红色、绿色和蓝色的值,每个值在 [0:255] 之间变化。
使用下面的代码,我可以得到正确的表面颜色投影,但是轮廓的线条颜色是错误的,根本没有变化。
set pm3d at s
set contour base
set cntrparam levels discrete 7.245
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
splot 'data' u 1:2:3:(rgb($4,$5,$6)) w pm3d lw 2 lc rgb variable
有谁知道如何解决这个问题? 任何帮助深表感谢。
更新:如果有帮助,这里是我从上述脚本和相关数据文件中获得的 output。 如您所见,等高线不遵循投影到表面上的颜色图案。
为了获得具有可变线条颜色的轮廓,您需要在splot
中包含palette
命令。
set pm3d at s
set palette rgbformulae 33,13,10
set contour
set cntrparam levels 50
set zrange [:8]
#rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
splot 'data' u 1:2:3 w l ls 7 palette notitle
但是,基于 output 看起来您的数据在中心并没有太大变化以具有可变的线条颜色。 您还可以使用set contrparam levels
来更改轮廓的强度。
这是我对简化假设的建议,即在 60 度扇区内只有 3 个 colors(红色、绿色、蓝色)仅取决于x
和y
以及常数 colors。 如果这个假设不正确,请告诉我。
脚本:(使用 gnuplot 5.0.0 和 5.4.1 测试)
### variable color contour line
reset session
FILE = "SO73015796.dat"
set contour
set cntrparam levels discrete 7.245
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
set table $Contour
splot FILE u 1:2:3
unset table
set xyplane relative 0
unset contour
unset colorbox
set angle degrees
myColor(x,y) = (a=atan2(y,x), abs(sin(a))<sin(30) ? 0x00ff00 : \
abs(sin(a-60))<sin(30) ? 0xff0000 : 0x0000ff)
set key noautotitle
splot FILE u 1:2:3:(rgb($4,$5,$6)) w pm3d lc rgb var, \
$Contour u 1:2:(6.5):(myColor($1,$2)) index 1 w l lw 2 lc rgb var
### end of script
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.