如何在gnuplot中设置网格(矢量或箭头)线
例如,轴网线(平行于Y轴)在X轴的位置在文件的第三行定义 第三行有要点如何在gnuplot中设置网格(矢量或箭头)线,gnuplot,Gnuplot,例如,轴网线(平行于Y轴)在X轴的位置在文件的第三行定义 第三行有要点 # 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770 我可以从另一个定义为file with的文件中获取Ymax set table $Dummy plot FILE u ($0==1?(Ymax=$2): NaN) w table # i have updated this line. This will be used only for height o
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
我可以从另一个定义为file with的文件中获取Ymax
set table $Dummy
plot FILE u ($0==1?(Ymax=$2): NaN) w table # i have updated this line. This will be used only for height of the grid line. Here FILE is a data file with two columns only which will be plotted in X-Y format.
unset table
如何在上述位置设置应以Ymax结尾的网格线
我需要像这样的东西:
for i in 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
do
set arrow $i, Ymax lc rgb "black" dt 2 nohead
done
轴线放置在轴记号位置。主刻度(刻度级别0)和次刻度(刻度级别1)分别跟踪。也可以选择栅格线的线型。要在显示的x坐标处生成蓝色细垂直网格线,请使用小记号控制网格线:
set xtics add ( 0.00000000 1, 0.08329780 1, 0.11683890 1, 0.20013670 1, 0.23367770 1 )
set grid mx lt 0, lt 1 lw 0.5 lc "blue"
有关更多详细信息,请参见文档(帮助设置XTIC、帮助设置网格)。网格线放置在轴刻度位置。主刻度(刻度级别0)和次刻度(刻度级别1)分别跟踪。也可以选择栅格线的线型。要在显示的x坐标处生成蓝色细垂直网格线,请使用小记号控制网格线:
set xtics add ( 0.00000000 1, 0.08329780 1, 0.11683890 1, 0.20013670 1, 0.23367770 1 )
set grid mx lt 0, lt 1 lw 0.5 lc "blue"
更多详细信息,请参见文档(帮助设置xtics,帮助设置网格)。正如@Ethan已经指出的,网格线绑定到主要或次要TIC,并跨越整个图形。 但是你可以用向量绘制一些东西 顺便说一下,请注意,使用您的代码
set table $Dummy
plot FILE u ($0==1?(Ymin=$1,Ymax=$2):NaN,Xmax=$8) w table
unset table
Ymin
和Ymax
将是最后一个数据集第二行(行)的第一列和第二列的值。如果数据没有空行,则最后一个数据集也是第一个数据集Xmax
将是第8列的最后一个总值
对于您的任务,一个解决方案可以是以下内容。不需要sed或awk等。
因为我没有你提供的示例数据,所以我假设了一些东西
Ymin、Ymax、Xmax
,用矢量绘制“网格线”
strcol()
限制为(我猜)63个字符。通过gnuplot 5.2.7,这一点已经得到了修复
代码:
### use vector plot to plot "grid lines"
reset session
$Data1 <<EOD
# first line
# second line
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
# below this line data starts
1 4
2 5
3 6
EOD
$Data2 <<EOD
1.1 2.7 0 0 1.2 0 0 0.00
1.2 2.6 0 0 1.8 0 0 0.05
1.3 2.5 0 0 2.5 0 0 0.10
1.4 2.4 0 0 2.1 0 0 0.15
1.5 2.3 0 0 1.6 0 0 0.17
1.6 2.2 0 0 1.7 0 0 0.20
1.7 2.1 0 0 2.4 0 0 0.25
EOD
set table $Dummy
set datafile commentschars '' # all lines will be data line
set datafile separator '\n' # in order to get full lines
plot $Data1 u (xValues = strcol(1)) index 0 every ::2::2 w table # get the complete 3rd line
set datafile commentschars '#' # reset the comment character
set datafile separator whitespace # reset the column separator
plot t=0 $Data2 u (t==0?(Ymin=$1,Ymax=$2,t=1):NaN,Xmax=$8) w table # get Ymin,Ymax,Xmax
unset table
print Ymin, Ymax, Xmax, xValues
xValue(n) = real(word(xValues,n+1)) # function to extract xValue
set xrange[-0.05:0.3]
set samples words(xValues)-1 # set number of datapoints of special datafile '+'
plot '+' u (xValue(int($0+1))):(Ymin):(0):(Ymax-Ymin) w vectors lc rgb "black" dt 2 nohead not, \
$Data2 u 8:5 w lp pt 7 lc rgb "red" title "Data"
### end of code
### draw arrows from a data string
reset session
xValues = "0.00000000 0.08329780 0.11683890 0.20013670 0.23367770"
Ymin = 0.2
Ymax = 0.9
Xmax = 0.25
i=0
do for [xValue in xValues] {
i=i+1
set arrow i from xValue,Ymin to xValue,Ymax nohead dt 2
}
set xrange[-0.05:0.4]
set yrange[0:1]
plot x
### end of code
结果:
### use vector plot to plot "grid lines"
reset session
$Data1 <<EOD
# first line
# second line
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
# below this line data starts
1 4
2 5
3 6
EOD
$Data2 <<EOD
1.1 2.7 0 0 1.2 0 0 0.00
1.2 2.6 0 0 1.8 0 0 0.05
1.3 2.5 0 0 2.5 0 0 0.10
1.4 2.4 0 0 2.1 0 0 0.15
1.5 2.3 0 0 1.6 0 0 0.17
1.6 2.2 0 0 1.7 0 0 0.20
1.7 2.1 0 0 2.4 0 0 0.25
EOD
set table $Dummy
set datafile commentschars '' # all lines will be data line
set datafile separator '\n' # in order to get full lines
plot $Data1 u (xValues = strcol(1)) index 0 every ::2::2 w table # get the complete 3rd line
set datafile commentschars '#' # reset the comment character
set datafile separator whitespace # reset the column separator
plot t=0 $Data2 u (t==0?(Ymin=$1,Ymax=$2,t=1):NaN,Xmax=$8) w table # get Ymin,Ymax,Xmax
unset table
print Ymin, Ymax, Xmax, xValues
xValue(n) = real(word(xValues,n+1)) # function to extract xValue
set xrange[-0.05:0.3]
set samples words(xValues)-1 # set number of datapoints of special datafile '+'
plot '+' u (xValue(int($0+1))):(Ymin):(0):(Ymax-Ymin) w vectors lc rgb "black" dt 2 nohead not, \
$Data2 u 8:5 w lp pt 7 lc rgb "red" title "Data"
### end of code
### draw arrows from a data string
reset session
xValues = "0.00000000 0.08329780 0.11683890 0.20013670 0.23367770"
Ymin = 0.2
Ymax = 0.9
Xmax = 0.25
i=0
do for [xValue in xValues] {
i=i+1
set arrow i from xValue,Ymin to xValue,Ymax nohead dt 2
}
set xrange[-0.05:0.4]
set yrange[0:1]
plot x
### end of code
正如@Ethan已经指出的,网格线被绑定到主要或次要TIC,并跨越整个图形。 但是你可以用向量绘制一些东西 顺便说一下,请注意,使用您的代码
set table $Dummy
plot FILE u ($0==1?(Ymin=$1,Ymax=$2):NaN,Xmax=$8) w table
unset table
Ymin
和Ymax
将是最后一个数据集第二行(行)的第一列和第二列的值。如果数据没有空行,则最后一个数据集也是第一个数据集Xmax
将是第8列的最后一个总值
对于您的任务,一个解决方案可以是以下内容。不需要sed或awk等。
因为我没有你提供的示例数据,所以我假设了一些东西
Ymin、Ymax、Xmax
,用矢量绘制“网格线”
strcol()
限制为(我猜)63个字符。通过gnuplot 5.2.7,这一点已经得到了修复
代码:
### use vector plot to plot "grid lines"
reset session
$Data1 <<EOD
# first line
# second line
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
# below this line data starts
1 4
2 5
3 6
EOD
$Data2 <<EOD
1.1 2.7 0 0 1.2 0 0 0.00
1.2 2.6 0 0 1.8 0 0 0.05
1.3 2.5 0 0 2.5 0 0 0.10
1.4 2.4 0 0 2.1 0 0 0.15
1.5 2.3 0 0 1.6 0 0 0.17
1.6 2.2 0 0 1.7 0 0 0.20
1.7 2.1 0 0 2.4 0 0 0.25
EOD
set table $Dummy
set datafile commentschars '' # all lines will be data line
set datafile separator '\n' # in order to get full lines
plot $Data1 u (xValues = strcol(1)) index 0 every ::2::2 w table # get the complete 3rd line
set datafile commentschars '#' # reset the comment character
set datafile separator whitespace # reset the column separator
plot t=0 $Data2 u (t==0?(Ymin=$1,Ymax=$2,t=1):NaN,Xmax=$8) w table # get Ymin,Ymax,Xmax
unset table
print Ymin, Ymax, Xmax, xValues
xValue(n) = real(word(xValues,n+1)) # function to extract xValue
set xrange[-0.05:0.3]
set samples words(xValues)-1 # set number of datapoints of special datafile '+'
plot '+' u (xValue(int($0+1))):(Ymin):(0):(Ymax-Ymin) w vectors lc rgb "black" dt 2 nohead not, \
$Data2 u 8:5 w lp pt 7 lc rgb "red" title "Data"
### end of code
### draw arrows from a data string
reset session
xValues = "0.00000000 0.08329780 0.11683890 0.20013670 0.23367770"
Ymin = 0.2
Ymax = 0.9
Xmax = 0.25
i=0
do for [xValue in xValues] {
i=i+1
set arrow i from xValue,Ymin to xValue,Ymax nohead dt 2
}
set xrange[-0.05:0.4]
set yrange[0:1]
plot x
### end of code
结果:
### use vector plot to plot "grid lines"
reset session
$Data1 <<EOD
# first line
# second line
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
# below this line data starts
1 4
2 5
3 6
EOD
$Data2 <<EOD
1.1 2.7 0 0 1.2 0 0 0.00
1.2 2.6 0 0 1.8 0 0 0.05
1.3 2.5 0 0 2.5 0 0 0.10
1.4 2.4 0 0 2.1 0 0 0.15
1.5 2.3 0 0 1.6 0 0 0.17
1.6 2.2 0 0 1.7 0 0 0.20
1.7 2.1 0 0 2.4 0 0 0.25
EOD
set table $Dummy
set datafile commentschars '' # all lines will be data line
set datafile separator '\n' # in order to get full lines
plot $Data1 u (xValues = strcol(1)) index 0 every ::2::2 w table # get the complete 3rd line
set datafile commentschars '#' # reset the comment character
set datafile separator whitespace # reset the column separator
plot t=0 $Data2 u (t==0?(Ymin=$1,Ymax=$2,t=1):NaN,Xmax=$8) w table # get Ymin,Ymax,Xmax
unset table
print Ymin, Ymax, Xmax, xValues
xValue(n) = real(word(xValues,n+1)) # function to extract xValue
set xrange[-0.05:0.3]
set samples words(xValues)-1 # set number of datapoints of special datafile '+'
plot '+' u (xValue(int($0+1))):(Ymin):(0):(Ymax-Ymin) w vectors lc rgb "black" dt 2 nohead not, \
$Data2 u 8:5 w lp pt 7 lc rgb "red" title "Data"
### end of code
### draw arrows from a data string
reset session
xValues = "0.00000000 0.08329780 0.11683890 0.20013670 0.23367770"
Ymin = 0.2
Ymax = 0.9
Xmax = 0.25
i=0
do for [xValue in xValues] {
i=i+1
set arrow i from xValue,Ymin to xValue,Ymax nohead dt 2
}
set xrange[-0.05:0.4]
set yrange[0:1]
plot x
### end of code
这对我没有帮助。应该有一些脚本(可以在gnuplot中使用),它可以自动收集网格线位置,并在每个位置上显示网格线直到Ymax(Ymax在我的原始帖子中定义)。网格线始终跨越绘图的整个高度或宽度。这对我没有帮助。应该有一些脚本(可以在gnuplot中使用),它可以自动收集网格线位置,并在每个位置上显示网格线,直到Ymax(Ymax在我的原始帖子中定义)。网格线始终跨越绘图的整个高度或宽度。我可以直接从数据文件中grep xValues吗?在终端上,我可以得到它们:head-n332.dat | tail-n1 | tr-d'#'类似于xValues=“(head-n332.dat | tail-n1 | tr-d'#”)很高兴它终于成功了。如果答案是可以接受的,请将其标记为可以接受,您的问题将显示为已回答。先生,其他评论的解决方案是什么?关于“直接”从数据文件中删除数据?对不起,我不知道sed、awk或其他Unix实用程序。我可以直接从数据文件中grep xValues吗?在终端上,我可以得到它们:head-n332.dat | tail-n1 | tr-d'#'类似于xValues=“(head-n332.dat | tail-n1 | tr-d'#”)很高兴它终于成功了。如果答案是可以接受的,请将其标记为可以接受,您的问题将显示为已回答。先生,其他评论的解决方案是什么?关于“直接”从数据文件中删除数据?对不起,我不知道sed、awk或其他Unix实用程序。