gnuplot:有没有一种方法可以在空间上绘制垂直线?

gnuplot:有没有一种方法可以在空间上绘制垂直线?,plot,graph,gnuplot,Plot,Graph,Gnuplot,我试图绘制一个变量的几条垂直线,比如速度(m/s),与距离(m)的x轴和高度(m)的y轴相对。每个速度剖面都是在不同位置测得的高度的函数。因此,我们的目的是观察这些剖面在空间上是如何变化的 我曾想过通过将垂直剖面移动x分量来实现这一点,x分量对应于测量每个剖面的位置。因此,如果我们假设第二个x轴描述了速度,我希望它在每个测量点重置为0 预期结果草图(忽略黑色): 有人知道正确的行动方针是什么吗?我正在使用gnuplot,但欢迎任何替代方案。提前谢谢 编辑: 下面您可以看看我使用的数据(代码段中

我试图绘制一个变量的几条垂直线,比如速度(m/s),与距离(m)的x轴和高度(m)的y轴相对。每个速度剖面都是在不同位置测得的高度的函数。因此,我们的目的是观察这些剖面在空间上是如何变化的

我曾想过通过将垂直剖面移动x分量来实现这一点,x分量对应于测量每个剖面的位置。因此,如果我们假设第二个x轴描述了速度,我希望它在每个测量点重置为0

预期结果草图(忽略黑色):

有人知道正确的行动方针是什么吗?我正在使用gnuplot,但欢迎任何替代方案。提前谢谢

编辑:

下面您可以看看我使用的数据(代码段中的文件配置文件)

z(m) U_1(米/秒)* U_4(米/秒)* U_8(米/秒)* 0.50 1.66 1.82 1.95 0.75 1.85 2.04 2.11 1 2 2.20 2.18 1.25 2.12 2.34 2.21 1.50 2.23 2.36 2.22 1.75 2.33 2.37 2.22 2 2.41 2.38 2.22
假设我正确理解你的意图,这将是我的建议。 您希望通过
1
4
8
偏移x数据,因此必须将这些值添加到列
$2
$3
$4
。 如果我正确理解了0 m/s的草图,您还需要从中减去第一个速度值。 如果我错了,请纠正我。 因此,我们使用伪列0(检查
帮助伪列
),它基本上是从0开始的行号。如果
$0==0
(检查三元运算符
帮助三元
),则将列的当前值(仅第一个值)指定给变量,例如
xoff=$2
,并从列中的所有后续值中减去它。由于您有一个标题,因此必须跳过一行,即
跳过1

如果您希望在顶部有多个x轴,所有x轴都从0开始,可以使用箭头和标签来完成,也可以使用multiplot来完成,具体取决于您需要什么(请检查
帮助multiplot

检查以下各项作为起点:

代码:

### plotting with different offsets
reset session

$Data <<EOD
z(m)  U_1(m/s)*  U_4(m/s)*  U_8(m/s)*
0.50       1.66       1.82       1.95
0.75       1.85       2.04       2.11
1.00       2.00       2.20       2.18
1.25       2.12       2.34       2.21
1.50       2.23       2.36       2.22
1.75       2.33       2.37       2.22
2.00       2.41       2.38       2.22
EOD

set xrange[0:10]
set xtics 1
set yrange [0.3:2.4]
set grid xtics, ytics

vs = "1 4 8"
set for [v in vs] arrow from v, graph 0 to v, graph 1 lw 1.5 lc "black" dt 2 nohead

plot $Data u ($0==0?xoff=$2:0, $2+1-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "red"   ti "U_1", \
     ''    u ($0==0?xoff=$3:0, $3+4-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "green" ti "U_4", \
     ''    u ($0==0?xoff=$4:0, $4+8-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "black" ti "U_8"
### end of code
### plotting with different offsets
reset session

$Data <<EOD
z(m)  U_1(m/s)*  U_4(m/s)*  U_8(m/s)*
0.50       1.66       1.82       1.95
0.75       1.85       2.04       2.11
1.00       2.00       2.20       2.18
1.25       2.12       2.34       2.21
1.50       2.23       2.36       2.22
1.75       2.33       2.37       2.22
2.00       2.41       2.38       2.22
EOD

set for [v in "1 4 8"] arrow from v, graph 0 to v, graph 1 lw 1.5 lc "black" dt 2 nohead

XFirstToGrphRel(x) = (x-MainXMin)/(MainXMax - MainXMin)   # relative position to graph 
YFirstToGrphRel(y) = (y-MainYMin)/(MainYMax - MainYMin)
PosX(x) = XminScrRel+GraphInScrSizeX*XFirstToGrphRel(x)   # screen positon of the subplot
PosY(y) = YminScrRel+GraphInScrSizeY*YFirstToGrphRel(y)
SizeX(dx) = GraphInScrSizeX*dx/(MainXMax - MainXMin)      # screen size of a subplot 
SizeY(dy) = GraphInScrSizeY*dy/(MainYMax - MainYMin)

set multiplot 

    set xlabel "x / m"
    set xrange[0:12]
    set xtics 1
    set ylabel "z / m"
    set yrange [0.3:2.4]
    set ytics 0.5
    set grid xtics, ytics

    plot 0 w p ps 0 notitle    # plot nothing, just background plot
    # store the current terminal values for later use
    MainXMin = GPVAL_X_MIN
    MainXMax = GPVAL_X_MAX
    MainYMin = GPVAL_Y_MIN
    MainYMax = GPVAL_Y_MAX
    GraphInScrSizeX = real(GPVAL_TERM_XMAX-GPVAL_TERM_XMIN)/GPVAL_TERM_XSIZE*GPVAL_TERM_SCALE  # real() to avoid integer division
    GraphInScrSizeY = real(GPVAL_TERM_YMAX-GPVAL_TERM_YMIN)/GPVAL_TERM_YSIZE*GPVAL_TERM_SCALE
    XminScrRel = real(GPVAL_TERM_XMIN)/GPVAL_TERM_XSIZE*GPVAL_TERM_SCALE   
    YminScrRel = real(GPVAL_TERM_YMIN)/GPVAL_TERM_YSIZE*GPVAL_TERM_SCALE

    unset arrow
    set margins 0,0,0,0
    unset xlabel
    unset xtics
    set x2label "v / m/s"
    set x2range [0:2.5]
    set x2tics 0.5 offset 0.5
    unset ylabel
    set format y ""
    set yrange [0.5:2.0]
    set grid x2tics, ytics
    
    set object 1 rect from graph 0, graph 0 to graph 1, graph 1 behind fc "white"
    set size SizeX(2),SizeY(1.5)

    set origin PosX(1),PosY(0.5)
    plot $Data u 2:1 axes x2y1 w lp pt 7 lc "red" notitle
    
    set origin PosX(4.0),PosY(0.5)
    plot $Data u 3:1 axes x2y1 w lp pt 7 lc "green" notitle
    
    set origin PosX(8.0),PosY(0.5)
    plot $Data u 4:1 axes x2y1 w lp pt 7 lc "blue" notitle
    
unset multiplot
### end of code
结果:

### plotting with different offsets
reset session

$Data <<EOD
z(m)  U_1(m/s)*  U_4(m/s)*  U_8(m/s)*
0.50       1.66       1.82       1.95
0.75       1.85       2.04       2.11
1.00       2.00       2.20       2.18
1.25       2.12       2.34       2.21
1.50       2.23       2.36       2.22
1.75       2.33       2.37       2.22
2.00       2.41       2.38       2.22
EOD

set xrange[0:10]
set xtics 1
set yrange [0.3:2.4]
set grid xtics, ytics

vs = "1 4 8"
set for [v in vs] arrow from v, graph 0 to v, graph 1 lw 1.5 lc "black" dt 2 nohead

plot $Data u ($0==0?xoff=$2:0, $2+1-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "red"   ti "U_1", \
     ''    u ($0==0?xoff=$3:0, $3+4-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "green" ti "U_4", \
     ''    u ($0==0?xoff=$4:0, $4+8-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "black" ti "U_8"
### end of code
### plotting with different offsets
reset session

$Data <<EOD
z(m)  U_1(m/s)*  U_4(m/s)*  U_8(m/s)*
0.50       1.66       1.82       1.95
0.75       1.85       2.04       2.11
1.00       2.00       2.20       2.18
1.25       2.12       2.34       2.21
1.50       2.23       2.36       2.22
1.75       2.33       2.37       2.22
2.00       2.41       2.38       2.22
EOD

set for [v in "1 4 8"] arrow from v, graph 0 to v, graph 1 lw 1.5 lc "black" dt 2 nohead

XFirstToGrphRel(x) = (x-MainXMin)/(MainXMax - MainXMin)   # relative position to graph 
YFirstToGrphRel(y) = (y-MainYMin)/(MainYMax - MainYMin)
PosX(x) = XminScrRel+GraphInScrSizeX*XFirstToGrphRel(x)   # screen positon of the subplot
PosY(y) = YminScrRel+GraphInScrSizeY*YFirstToGrphRel(y)
SizeX(dx) = GraphInScrSizeX*dx/(MainXMax - MainXMin)      # screen size of a subplot 
SizeY(dy) = GraphInScrSizeY*dy/(MainYMax - MainYMin)

set multiplot 

    set xlabel "x / m"
    set xrange[0:12]
    set xtics 1
    set ylabel "z / m"
    set yrange [0.3:2.4]
    set ytics 0.5
    set grid xtics, ytics

    plot 0 w p ps 0 notitle    # plot nothing, just background plot
    # store the current terminal values for later use
    MainXMin = GPVAL_X_MIN
    MainXMax = GPVAL_X_MAX
    MainYMin = GPVAL_Y_MIN
    MainYMax = GPVAL_Y_MAX
    GraphInScrSizeX = real(GPVAL_TERM_XMAX-GPVAL_TERM_XMIN)/GPVAL_TERM_XSIZE*GPVAL_TERM_SCALE  # real() to avoid integer division
    GraphInScrSizeY = real(GPVAL_TERM_YMAX-GPVAL_TERM_YMIN)/GPVAL_TERM_YSIZE*GPVAL_TERM_SCALE
    XminScrRel = real(GPVAL_TERM_XMIN)/GPVAL_TERM_XSIZE*GPVAL_TERM_SCALE   
    YminScrRel = real(GPVAL_TERM_YMIN)/GPVAL_TERM_YSIZE*GPVAL_TERM_SCALE

    unset arrow
    set margins 0,0,0,0
    unset xlabel
    unset xtics
    set x2label "v / m/s"
    set x2range [0:2.5]
    set x2tics 0.5 offset 0.5
    unset ylabel
    set format y ""
    set yrange [0.5:2.0]
    set grid x2tics, ytics
    
    set object 1 rect from graph 0, graph 0 to graph 1, graph 1 behind fc "white"
    set size SizeX(2),SizeY(1.5)

    set origin PosX(1),PosY(0.5)
    plot $Data u 2:1 axes x2y1 w lp pt 7 lc "red" notitle
    
    set origin PosX(4.0),PosY(0.5)
    plot $Data u 3:1 axes x2y1 w lp pt 7 lc "green" notitle
    
    set origin PosX(8.0),PosY(0.5)
    plot $Data u 4:1 axes x2y1 w lp pt 7 lc "blue" notitle
    
unset multiplot
### end of code

欢迎来到StackOverflow!如果我们不知道您的数据格式是什么样子,就很难提出任何建议。请提供示例数据,以防您有一些gnuplot代码。您好,您有每个速度和高度的x组件吗?您好,谢谢关心。我根据@theozh评论编辑了我的帖子。速度剖面的x分量分别为1米、4米和8米,但任何抽象数字都应该有效。这是一项有趣的工作。提供的数据与草图不匹配。草图中的0值表示垂直虚线用作速度剖面的原点。因此,正值位于虚线的右侧,而负值位于左侧。我认为不必用第一个值进行减法,我可以用一个比例因子乘以每个值,以避免出现大数字(大于最大x分量)。@petrosca我想最好使用
multiplot
,因为据我所知,您希望在“主”图中对齐子图。请参见修改后的答案。@petrosca更概括一点,另请参见此处: