【问题标题】:Combining acspline with filledcurve on data将acspline与数据填充曲线相结合
【发布时间】:2023-03-16 22:01:01
【问题描述】:

我知道如何使用 filledcurveusing 1:2:3 来填充第 2 列和第 3 列描述的曲线之间的区域。

我也知道如何使用带有using 1:2:(0.1) 的acsplines 来平滑单个曲线(0.1 是每个点的平滑权重)。

但我未能将两者结合起来,即填充两条平滑曲线之间的区域。我尝试的所有变体都会给我错误消息,例如duplicated or contradicting arguments in datafile options

这是我尝试过的:

plot 'datafile' using 1:2:3:(0.1):(0.1) smooth acs with lines
plot 'datafile' using 1:2:(0.1):3:(0.1) smooth acs with lines

这种组合可能吗?那么语法如何呢?

【问题讨论】:

    标签: gnuplot bezier curve spline smoothing


    【解决方案1】:

    我猜你不能将smooth acsplinewith filledcurves 结合起来,但我也不知道为什么这不可能。 好吧,作为一种解决方法,首先将您的 smooth acspline 曲线绘制到数据表中,然后将其绘制为 with filledcurves

    代码:

    ### filled acspline curve
    reset session
    
    $Data <<EOD
    1 2
    2 4
    3 3
    4 1
    EOD
    
    # plot your acspline data into a table
    set table $ACSpline
        plot $Data u 1:2 smooth acspline
    unset table
    
    set style fill transparent solid 0.1 
    
    plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Original data", \
         $Data u 1:2 smooth acspline lw 2 lc rgb "red" ti "acspline", \
         $ACSpline u 1:2 w filledcurves x1 lc rgb "red" ti "acspline filled"
    ### end of code
    

    结果:

    加法:

    还有另一种方法可以将数据放入表中。检查help set print。 这样,您可以将两条样条的数据放入一个数据块中,并可以绘制它们之间的区域。也许有人知道实现这一目标的更简单方法。

    代码:

    ### filled curve between two acsplines
    reset session
    
    $Data <<EOD
    1 2 4
    2 4 1
    3 3 0
    4 1 3
    EOD
    
    # plot your acspline data into tables
    set table $ACSpline1
        plot $Data u 1:2:(1) smooth acspline
    unset table
    set table $ACSpline2
        plot $Data u 1:3:(1) smooth acspline
    unset table
    set print $BetweenSplines
        do for [i=1:|$ACSpline1|] {
            print sprintf("%s %s %s",word($ACSpline1[i],1),word($ACSpline1[i],2),word($ACSpline2[i],2))
        }
    set print
    
    set style fill transparent solid 0.5 
    
    plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Original data col 2", \
         $Data u 1:3 w lp pt 7 lc rgb "blue" ti "Original data col 3", \
         $ACSpline1 u 1:2 w l lw 2 lc rgb "red" ti "acspline col 2", \
         $ACSpline2 u 1:2 w l lw 2 lc rgb "green" ti "acspline col 3", \
         $BetweenSplines u 1:2:3 w filledcurves lc rgb "yellow" ti "acspline filled"
    ### end of code
    

    结果:

    【讨论】:

    • 确实很有趣(我不知道这个表格功能)。但是……我怎样才能用它来填充两条曲线之间的区域?您只填充 一条 曲线和轴之间的区域。
    • 对不起,我没有仔细阅读。您希望它填充两条 acsplines 曲线之间。嗯,不知何故,您需要将平滑后的数据放入 one 数据块的两列中。我确信有办法。我需要考虑一下。
    • 这个解决方案有点老套,但很有效! (我更喜欢更容易理解的代码,因为它有可维护的代码。)特别是,因为我的 X 坐标是特定格式的日期时间,我需要确保打印时间以与解析时相同的格式完成,并且生成表(数据块)会在 datetimes(!) 周围添加双引号,这会被打印再次删除。但是在弄清楚这一切之后,它奏效了!非常感谢:-)
    • 很高兴听到它最终以某种方式对您有用。嗯,日期时间是我直到现在才知道的信息。 gnuplot 人(在 Linux 上)倾向于使用外部工具来(重新)排列或处理数据,但只要您可以使用 gnuplot 来完成,我更喜欢独立于平台的纯 gnuplot 解决方案。
    • 是的。日期时间的东西应该更透明。谁会猜到我使用的是日期时间还是简单的数字会有所不同? ;-)
    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多