gnuplot:有没有办法在空间上绘制垂直线?
gnuplot: Is there a way to plot vertical lines spatially?
我正在尝试根据距离 (m) 的 x-axis 和高度 (m) 的 y-axis 绘制变量的几条垂直线,比如速度 (m/s) ).每个速度剖面都是在不同位置测量的高度的函数。所以目的是观察这些剖面如何在空间上发生变化。
我想通过将垂直剖面移动对应于每个剖面测量位置的 x-component 来解决这个问题。因此,如果我们假设第二个 x-axis 描述了速度,我希望它在每个测量点都重置为 0。
期望结果草图(忽略黑色):
有人知道正确的做法是什么吗?我正在使用 gnuplot 但欢迎使用任何替代方法。提前致谢。
编辑:
下面你可以看看我使用的数据(代码段中的文件verProfiles)
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
*上面 table 中 U 变量名称中的数字 1、4 和 8 表示进行测量的位置,因此每个 U 剖面应该开始,并且图表中相应的 x 点。
到目前为止,我编写的生成 false 图的 gnuplot 代码是:
outName="U_test.png"
set terminal pngcairo font "helvetica,20" size 800, 1000
set xtics nomirror
set x2tics
set xrange [0:10] noreverse nowriteback
set autoscale x2fix
set yrange [0:2.5]
set grid
set mxtics 4
set mx2tics 4
set mytics 4
set key left top
set key samplen 2
set key spacing 0.75
set xlabel "x"
set x2label "Ux [m s^{-1}]"
set ylabel "z"
set output "$outName"
inp0="verProfiles"
plot \
inp0 u 2:1 t "U_1" axes x2y1 w lp ps 2 lw 2 lc rgb "#009E73", \
inp0 u 3:1 t "U_4" axes x2y1 w lp ps 2 lw 2 lc rgb "#3F8B77", \
inp0 u 4:1 t "U_8" axes x2y1 w lp ps 2 lw 2 lc rgb "#7EA99E"
生成的假图为:
假设我正确理解了您的意图,这就是我的建议。
您想要将 x-data 偏移 1
、4
和 8
,因此您必须将这些值添加到列 </code>、<code>
, </code>.
如果我用 0 m/s 正确理解你的草图,你还想从中减去第一个速度值。
如果我错了,请纠正我。
因此,您采用伪列 0(检查 <code>help pseudocolumns
),它基本上是从 0 开始的行号。如果 [=19=]==0
(检查三元运算符 help ternary
),您分配当前值(仅列的第一个值)到一个变量,例如xoff=
并从您列中的所有后续值中减去它。因为你有 header 你必须跳过一行,即 skip 1
.
如果你想要几个 x-axes 在最上面,全部从 0 开始,这可以用箭头和标签来完成,或者取决于你究竟需要什么,可能用多图(检查 help 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 ([=10=]==0?xoff=:0, +1-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "red" ti "U_1", \
'' u ([=10=]==0?xoff=:0, +4-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "green" ti "U_4", \
'' u ([=10=]==0?xoff=:0, +8-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "black" ti "U_8"
### end of code
结果:
加法:
也许现在我对你可能想要的东西有了更好的了解。
我猜你“只是”想在“主要”情节中的定义位置有子情节。
gnuplot 提供了 multiplot
(检查 help multiplot
)的特性,它将多个图彼此相邻或重叠放置。
您可以定义每个子图的原点(选中 help origin
)和大小(选中 help size
)。
但是,子图的坐标和大小以屏幕坐标给出。
现在的问题是:如何将地块放置在相对于第一个地块的所需位置?
对于标签、箭头和 objects,您可以使用屏幕、图形和轴坐标(检查 help coordinates
),但我不知道您可以使用上一个绘图的轴坐标。
因此,您必须使用一些内部 gnuplot 变量 GPVAL_...
自己计算这些位置。看起来很复杂其实就是一些坐标变换
代码:
### 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
结果:
我正在尝试根据距离 (m) 的 x-axis 和高度 (m) 的 y-axis 绘制变量的几条垂直线,比如速度 (m/s) ).每个速度剖面都是在不同位置测量的高度的函数。所以目的是观察这些剖面如何在空间上发生变化。
我想通过将垂直剖面移动对应于每个剖面测量位置的 x-component 来解决这个问题。因此,如果我们假设第二个 x-axis 描述了速度,我希望它在每个测量点都重置为 0。
期望结果草图(忽略黑色):
有人知道正确的做法是什么吗?我正在使用 gnuplot 但欢迎使用任何替代方法。提前致谢。
编辑:
下面你可以看看我使用的数据(代码段中的文件verProfiles)
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 |
*上面 table 中 U 变量名称中的数字 1、4 和 8 表示进行测量的位置,因此每个 U 剖面应该开始,并且图表中相应的 x 点。
到目前为止,我编写的生成 false 图的 gnuplot 代码是:
outName="U_test.png"
set terminal pngcairo font "helvetica,20" size 800, 1000
set xtics nomirror
set x2tics
set xrange [0:10] noreverse nowriteback
set autoscale x2fix
set yrange [0:2.5]
set grid
set mxtics 4
set mx2tics 4
set mytics 4
set key left top
set key samplen 2
set key spacing 0.75
set xlabel "x"
set x2label "Ux [m s^{-1}]"
set ylabel "z"
set output "$outName"
inp0="verProfiles"
plot \
inp0 u 2:1 t "U_1" axes x2y1 w lp ps 2 lw 2 lc rgb "#009E73", \
inp0 u 3:1 t "U_4" axes x2y1 w lp ps 2 lw 2 lc rgb "#3F8B77", \
inp0 u 4:1 t "U_8" axes x2y1 w lp ps 2 lw 2 lc rgb "#7EA99E"
生成的假图为:
假设我正确理解了您的意图,这就是我的建议。
您想要将 x-data 偏移 1
、4
和 8
,因此您必须将这些值添加到列 </code>、<code>
, </code>.
如果我用 0 m/s 正确理解你的草图,你还想从中减去第一个速度值。
如果我错了,请纠正我。
因此,您采用伪列 0(检查 <code>help pseudocolumns
),它基本上是从 0 开始的行号。如果 [=19=]==0
(检查三元运算符 help ternary
),您分配当前值(仅列的第一个值)到一个变量,例如xoff=
并从您列中的所有后续值中减去它。因为你有 header 你必须跳过一行,即 skip 1
.
如果你想要几个 x-axes 在最上面,全部从 0 开始,这可以用箭头和标签来完成,或者取决于你究竟需要什么,可能用多图(检查 help 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 ([=10=]==0?xoff=:0, +1-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "red" ti "U_1", \
'' u ([=10=]==0?xoff=:0, +4-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "green" ti "U_4", \
'' u ([=10=]==0?xoff=:0, +8-xoff):1 skip 1 w lp ps 1.5 lw 2 pt 7 lc "black" ti "U_8"
### end of code
结果:
加法:
也许现在我对你可能想要的东西有了更好的了解。
我猜你“只是”想在“主要”情节中的定义位置有子情节。
gnuplot 提供了 multiplot
(检查 help multiplot
)的特性,它将多个图彼此相邻或重叠放置。
您可以定义每个子图的原点(选中 help origin
)和大小(选中 help size
)。
但是,子图的坐标和大小以屏幕坐标给出。
现在的问题是:如何将地块放置在相对于第一个地块的所需位置?
对于标签、箭头和 objects,您可以使用屏幕、图形和轴坐标(检查 help coordinates
),但我不知道您可以使用上一个绘图的轴坐标。
因此,您必须使用一些内部 gnuplot 变量 GPVAL_...
自己计算这些位置。看起来很复杂其实就是一些坐标变换
代码:
### 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
结果: