如何在 gnuplot 中设置网格(矢量或箭头)线
How to set grid (vector or arrows) lines in gnuplot
X轴的网格线(平行于Y轴)的位置定义在文件的第三行,例如。
第三行有分
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
我可以从定义为 FILE 的另一个文件中获取 Ymax
set table $Dummy
plot FILE u ([=11=]==1?(Ymax=): 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"
如往常一样,请参阅文档(帮助设置 xtics、帮助设置网格)以获取更多详细信息。
正如@Ethan 已经指出的那样,网格线绑定到主要或次要抽动并跨越整个图表。
但是你可以绘制一些东西 with vectors
.
顺便说一下,请注意您的代码
set table $Dummy
plot FILE u ([=10=]==1?(Ymin=,Ymax=):NaN,Xmax=) w table
unset table
Ymin
和 Ymax
将是 last 数据集第二行(行)的第一列和第二列的值。如果您的数据没有空行,那么最后一个数据集也是第一个。 Xmax
将是第 8 列的总最后值。
对于您的任务,一种解决方案可能如下所示。不需要 sed 或 awk 等。
由于我没有您提供的示例数据,我假设了一些东西。
- 从一个数据文件中获取 "grid lines" 的 x 位置
- 从另一个数据文件中提取
Ymin,Ymax,Xmax
- 绘制数据
with linespoints
和 "grid lines" with vectors
请注意,在早期的 gnuplot 版本中,有 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=,Ymax=,t=1):NaN,Xmax=) 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([=11=]+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
结果:
加法:
上面我向您展示了如何使用 gnuplot 提取必要的值。
是的,这不是那么容易理解,也不是最短的方法,但它 gnuplot only!如果您更喜欢使用 sed、awk 等,请随意,但我无能为力。
另一种不绘制矢量的方法是绘制箭头。假设您的变量中已经有数据。
代码:
### 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
结果:
X轴的网格线(平行于Y轴)的位置定义在文件的第三行,例如。
第三行有分
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
我可以从定义为 FILE 的另一个文件中获取 Ymax
set table $Dummy
plot FILE u ([=11=]==1?(Ymax=): 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"
如往常一样,请参阅文档(帮助设置 xtics、帮助设置网格)以获取更多详细信息。
正如@Ethan 已经指出的那样,网格线绑定到主要或次要抽动并跨越整个图表。
但是你可以绘制一些东西 with vectors
.
顺便说一下,请注意您的代码
set table $Dummy
plot FILE u ([=10=]==1?(Ymin=,Ymax=):NaN,Xmax=) w table
unset table
Ymin
和 Ymax
将是 last 数据集第二行(行)的第一列和第二列的值。如果您的数据没有空行,那么最后一个数据集也是第一个。 Xmax
将是第 8 列的总最后值。
对于您的任务,一种解决方案可能如下所示。不需要 sed 或 awk 等。 由于我没有您提供的示例数据,我假设了一些东西。
- 从一个数据文件中获取 "grid lines" 的 x 位置
- 从另一个数据文件中提取
Ymin,Ymax,Xmax
- 绘制数据
with linespoints
和 "grid lines"with vectors
请注意,在早期的 gnuplot 版本中,有 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=,Ymax=,t=1):NaN,Xmax=) 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([=11=]+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
结果:
加法:
上面我向您展示了如何使用 gnuplot 提取必要的值。 是的,这不是那么容易理解,也不是最短的方法,但它 gnuplot only!如果您更喜欢使用 sed、awk 等,请随意,但我无能为力。
另一种不绘制矢量的方法是绘制箭头。假设您的变量中已经有数据。
代码:
### 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
结果: