【问题标题】:Gnuplot 3D - plot scatter points and a surface *and* lines between the themGnuplot 3D - 绘制散点和它们之间的表面*和*线
【发布时间】:2015-07-12 04:21:44
【问题描述】:

我一直无法找到制作标题中描述的情节的方法,如果可能的话,有人知道怎么做吗?我想从一个函数中绘制一个曲面,从一个文件中绘制点,并在点和曲面之间绘制线条。下面的链接是一张图片,其中包含我想做的一个示例,取自一个相同任务的 stackoverflow 问题(但针对不同的绘图程序)。

【问题讨论】:

  • 我可以编写一些循环遍历数据文件中的点的内容,并使用曲面图的方程计算与每个点的 (x,y) 对应的 z 值。然后创建另一个包含坐标对的文件(用于数据点和相应的表面点),并将其绘制为第三个数据系列。如果 gnuplot 中没有快速解决方案,我会这样做,但如果有人知道 gnuplot 方法,我会很感兴趣。

标签: plot 3d gnuplot surface scatter3d


【解决方案1】:

您可以在 gnuplot 的 using 语句中进行计算。对于线条,我使用vectors 绘图样式,使用arrowstyle variable(或linecolor variable),您可以根据dz 值选择不同的颜色:

set style arrow 1 linecolor rgb 'red' nohead
set style arrow 2 linecolor rgb 'green' nohead

splot f(x,y) with lines, \
    'points.dat' using 1:2:(f($1,$2)):(0):(0):(dz=$3-f($1,$2)):(dz < 0 ? 1 : 2) with vectors arrowstyle variable,\
    '' using 1:2:3 with points pt 7 ps 5

我不确定,这会给 gnuplot 4.6 带来问题。对于您的情况,您还可以使用 linecolor variable 或 linecolor rgb variable 更改垂直线的颜色:

splot f(x,y) with lines, \
    'points.dat' using 1:2:(f($1,$2)):(0):(0):(dz=$3-f($1,$2)):(dz < 0 ? 0xff0000 : 0x00ff00) with vectors nohead linecolor rgb variable lw 5,\
    '' using 1:2:3 with points pt 7 ps 5

【讨论】:

  • 太好了,谢谢。我有一个关于让它在特定的 gnuplot 版本上工作的问题。我将命令放入脚本并从 Windows 7 上的 gnuplot 调用它。它在 gnuplot v5 中完美运行。但是,在 v4.6 中,$ 符号必须更改为 $$。在那次更改之后,我收到一个错误“未找到箭头样式 0”,所以我认为它如何解析确定箭头样式的条件变量存在一些问题。知道如何纠正吗?
  • 即使我将 (dz &lt; 0 ? 1 : 2) 替换为 4 并在数据文件中添加第四列(包含数字“1”或“2”),我仍然得到“arrowstyle 0 not找到”错误消息。似乎 gnuplot v4.6 补丁级别 3 不喜欢 arrowstyle variable。我将只使用 v5 作为此图,因为它应该是一次性的。
  • 使用 linecolor rgb variable 甚至在 v4.6 中也有效。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多