【问题标题】:gnuplot: How to keep constant colors with splot and pm3d?gnuplot:如何使用 splot 和 pm3d 保持颜色不变?
【发布时间】:2019-09-14 02:51:52
【问题描述】:

基本上,我想通过参数splot(下图,顶部)绘制彩色球体。但是,我找不到使它们颜色一致的方法,但每个球体的颜色都不同。

我发现这篇文章 (Gnuplot, pm3d and surfaces) 让我通过首先将球体绘制到数据块然后绘制移位的数据块(下图,中间)来实现它。

现在,我想添加一些行。但是随后球体的颜色意外地改变了它们的颜色(下图,底部)。 为什么?如何避免?我怎样才能保持原本想要的颜色?

我的代码:

### connected 3D-spheres with splot and pm3d
reset session
set obj 1 rect from screen 0,0,0 to screen 1,1,0 behind 
set obj 1 rect fc rgb "black" fs solid 1.0
set view equal xyz
set view 45,45 
unset border
unset tics
unset colorbox

set style fill solid 1.0 noborder
set pm3d depthorder noborder
set pm3d lighting specular 0.5

set isosamples 50,50
set parametric
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
Radius = 1
set table $Sphere
    splot Radius*cos(u)*cos(v), Radius*cos(u)*sin(v), Radius*sin(u)
unset table
unset parametric

$Pos <<EOD
0 0 0
4 0 0
4 4 0
0 4 0
EOD

$Bonds <<EOD
0 0 0
4 0 0

4 0 0
4 4 0

4 4 0
0 4 0

0 4 0
0 0 0
EOD

PosX(i) = word($Pos[i],1)
PosY(i) = word($Pos[i],2)
PosZ(i) = word($Pos[i],3)

set palette defined (1 'red', 2 'green', 3 'blue', 4 'yellow')

set multiplot layout 3,1
    set parametric
        splot for [i=1:4] Radius*cos(u)*cos(v)+PosX(i), Radius*cos(u)*sin(v)+PosY(i), \
        Radius*sin(u)+PosZ(i) with pm3d not
    unset parametric
    unset obj 1 
    splot \
        for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)):(i) with pm3d not
    splot \
        for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)):(i) with pm3d not,\
        $Bonds u 1:2:3 w l lw 4 lc rgb "grey" not
unset multiplot
### end of code

结果:

【问题讨论】:

  • Fencepost 错误,我怀疑。在最终情节之前尝试set cbrange [1:4]
  • 谢谢你,这行得通!实际上,我也可以将set cbrange [1:4] 放在 first 情节之前。但我仍然不明白为什么只有当我有一个组合 splot-command 时才会发生这种情况:splot $Sphere .... , $Bonds .... 你所说的“栅栏柱”错误是什么意思?
  • 围栏长度为 N 个单位需要 N+1 个围栏柱。您已经定义了具有四种固定颜色的调色板。这些是“栅栏”。如果您希望固定颜色恰好落在 cb 的整数值上,则 cb 的总跨度必须为 3。最终绘图的 zrange 为 [0:4](所有“键”都位于 z=0)。所以总跨度为 4。如果您拉伸长度为 3 的调色板以跨越长度为 4 的 cb 范围,则固定颜色落在非整数值上。您可以通过固定 cb 的总跨度以匹配调色板的跨度来解决此问题。

标签: colors 3d gnuplot surface


【解决方案1】:

这是不涉及设置调色板的第二个解决方案。 请注意,这需要来自 gnuplot(5.3 版)开发分支的功能。它将出现在未来的稳定版本中,但尚未出现在版本 5.2.6 中。

[如前所述,后接]

set palette defined (1 'red', 2 'green', 3 'blue', 4 'yellow')
set style line 1 lc 'red'
set style line 2 lc 'green'
set style line 3 lc 'blue'
set style line 4 lc 'yellow'

set multiplot layout 1,3
    set parametric
        splot for [i=1:4] Radius*cos(u)*cos(v)+PosX(i), Radius*cos(u)*sin(v)+PosY(i), \
        Radius*sin(u)+PosZ(i) with pm3d not
    unset parametric
    unset obj 1
    splot \
        for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)):(i) with pm3d not
    splot \
        for [i=1:4] $Sphere u ($1+PosX(i)):($2+PosY(i)):($3+PosZ(i)) with pm3d fc ls i not,\
        $Bonds u 1:2:3 w l lw 4 lc rgb "grey" not
unset multiplot

with pm3d fc lt i 也可以工作(线型而不是线型)

【讨论】:

  • 不幸的是,with pm3d fc ls iwith pm3d fc lt i 不适合我。我收到错误 unexpected or unrecognized token 指向 fc。 (使用 gnuplot 5.2.6,Win7,wxt 终端)
  • 我将编辑答案,注意它需要更新版本的 gnuplot。
猜你喜欢
  • 2021-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多