【问题标题】:Gnuplot: Change Density of dotted line in splotGnuplot:改变splot中虚线的密度
【发布时间】:2016-10-22 09:32:02
【问题描述】:

我正在尝试在 Gnuplot 4.6 patchlevel 4 中使用以下代码在 splot 中绘制一条虚线:

set terminal "pdfcairo" enhanced dashed size 15,10
set pm3d map
set output "test.pdf"
splot 'map.dat' using 1:($2/1000):3 notitle, \
   'line1.dat' using 1:($2/1000):1 notitle with lines ls 2, \
   'line2.dat' using 1:($2/1000):1 notitle with lines ls 2
unset output

热图有效,line1.dat 也有效。然而,第二条线看起来大多是实心的。不同之处在于 line1.dat 有 70 个条目,而 line2.dat 有 900 个条目。第二行在两点之间有一个跳转,并在此处用虚线表示。

有人知道我可以如何更改点密度以使整条线显示为虚线。更改原始数据文件不是一种选择。

感谢您的帮助,

没有

编辑:

我发现的一种解决方法是

splot 'line2.dat' every ...

但这可能会在数据跳转时变得不方便。

【问题讨论】:

    标签: gnuplot heatmap dotted-line


    【解决方案1】:

    (s)plot 'line.dat' with lines 命令首先绘制数据点,然后使用具有相应线型的线连接数据点。如果数据点彼此过于接近,则在使用虚线样式时不会出现一些间隙。

    要显示虚线/虚线,可以尝试用函数替换点或减少点数。

    • 尝试用虚线代替虚线。 Linestyle 和 linecolor 可以独立设置:splot 'line.dat' with lines ls 0 lc 2。对于这种方法,900 分可能太多了。

    • 拟合函数是可行的,但可能很难找到合适的函数。

    • every 选项可减少点数。

    • 另一种减少点数的方法是使用smooth 选项对点进行插值。这需要一个临时文件,工作方式如下:

      # [prepare plot]
      set samples 100
      set table "line2.dat.tmp"
      plot 'line2.dat' using 1:($2/1000) smooth mcsplines with lines ls 2 
      unset table
      
      set terminal "pdfcairo" enhanced dashed size 15,10
      set pm3d map
      set output "test.pdf"
      
      # [plot]
      splot 'map.dat' using 1:($2/1000):3 notitle, \
         'line1.dat' using 1:($2/1000):1 notitle with lines ls 2, \
         'line2.dat.tmp' using 1:2:1 notitle with lines ls 2
      
      unset output
      

    在 [prepare plot] 部分中,创建了一个临时文件“line2.dat.tmp”,其中包含插值 line2.dat 的数据点。您必须使用set samples 来获得正确的分数。在示例中,我们有 100 个等距点,而不是 900 个不同距离的点。 smooth mcsplines 选项保留了原始数据点的单调性和凸性,请参阅 gnuplot shell 中的 help smooth mcsplines

    在 [plot] 部分中,原始“lines2.dat”被插值数据替换。

    如果原始数据足够平滑,以使 900 点替换为 100 点不会跳过重要信息,则此方法有效。也许您想在一个图表中同时绘制“lines2.dat”和“lines2.dat.tmp”来比较它们。

    【讨论】:

    • 感谢您的帮助。对于数据跳转,我使用了三个“每个”(一个用于第一部分,一个用于正确跳转,一个用于第二部分)。
    【解决方案2】:

    使用every 关键字,如下所示:

    'line2.dat' every 20 using 1:($2/1000):1 notitle with lines ls 2
    

    【讨论】:

      猜你喜欢
      • 2012-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      相关资源
      最近更新 更多