【问题标题】:Plotting intersecting lines in GNUplot在 GNUplot 中绘制相交线
【发布时间】:2019-03-24 15:18:20
【问题描述】:

我无法从搜索文档和演示中找到我在 GNUplot 中尝试做的任何示例。

基本上我想在 10/50/90% 标记处绘制我在此输出(用于演示)上手动绘制的蓝、绿和红线。

编辑:为清楚起见,我正在寻找分布线命中 0.1/0.5/0.9 处的累积分布的位置,以了解要绘制哪些坐标线在。谢谢!

set terminal png size 1600,800 font "Consolas" 16
set output "test.png"

set title "PDF and CDF - 1000 Simulations"
set grid y2
set ylabel "Date Probability"

set y2range [0:1.00]
set y2tics 0.1
set y2label "Cumulative Distribution"

set xtics rotate by 90 offset 0,-5

set bmargin 6

plot "data.txt" using 1:3:xtic(2) notitle with boxes axes x1y1,'' using 1:4 notitle with linespoints axes x1y2 

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    根据累积数据曲线中的点数,您可能需要插值。选择以下示例以使原始数据点不会位于您的级别 10%、50%、90%。如果您的数据没有稳定增加,它将采用与您的级别匹配的最后一个值。 程序如下:

    1. 将数据绘制到虚拟表中。
    2. 检查 Level 何时介于连续 y 值 (y0,y1) 之间。
    3. 记住 xp 中的插值 x 值。
    4. 从图形的边界向(xp,Level) 点绘制箭头(或者使用@Ethan 的部分外部矩形“技巧”)。

    代码:

    ### linear interpolation of data
    reset session
    set colorsequence classic
    set key left
    
    # create some dummy data
    set sample 10
    set table $Data
        plot [-2:2] '+' u 1:(norm(x)) with table
    unset table
    
    Interpolate(yi) = x0 + (x1-x0)*(yi-y0)/(y1-y0)
    
    Levels = "0.1 0.5 0.9"
    do for [i=1:words(Levels)] {
        Level = word(Levels,i)
        x0 = x1 = y0 = y1 = NaN
        set table $Dummy
            plot $Data u (x0=x1,x1=$1,y0=y1,y1=$2, (y0<=Level && Level<=y1)? (xp=Interpolate(Level)):NaN ): (Level) w table
        unset table
        set arrow i*2   from xp, graph 0 to xp,Level nohead lc i
        set arrow i*2+1 from xp,Level to graph 1,Level nohead lc i
    }
    
    plot $Data u 1:2 w lp pt 7 lc 0 t "Original data"
    ### end code
    

    结果:

    【讨论】:

    • 这个答案超出了预期,我将能够设计出如何将您的示例融入我的工作代码中。非常感谢。
    【解决方案2】:

    不清楚你是在问如何找到你的累积分布线达到 0.1、0.5、0.9 的 x 坐标(很难做到,我现在暂且不说)还是问如何画线一次你知道那些 x 值。后半部分很简单。将您要绘制的线条想象成从绘图延伸到右下角的矩形的未剪裁部分:

    set object 1 rectangle from x1, 0.1 to graph 2, -2 fillstyle empty border lc "blue"
    set object 2 rectangle from x2, 0.1 to graph 2, -2 fillstyle empty border lc "green"
    set object 3 rectangle from x3, 0.1 to graph 2, -2 fillstyle empty border lc "red"
    plot ...
    

    【讨论】:

    • 这有点帮助,但是是的,我也在试图找出累积分布线的位置。将修改问题。
    猜你喜欢
    • 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
    相关资源
    最近更新 更多