如何在gnuplot中设置网格线(矢量或箭头) [英] How to set grid (vector or arrows) lines in gnuplot
问题描述
在文件的第三行定义了网格线(平行于Y轴)在X轴上的位置,例如 第三行有点
The location of the grid lines (parallel to Y-axis) at X-axis are defined at third row of a files, for example the third lines has the points
# 0.00000000 0.08329780 0.11683890 0.20013670 0.23367770
我可以从另一个定义为FILE的文件中获得Ymax
I can get the Ymax from another file defined as FILE with
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 coloum only which will be plotted in X-Y format.
unset table
如何在上述应以Ymax结尾的位置设置网格线?
How I can set grid lines at above locations that should end to 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
推荐答案
正如@Ethan已经指出的那样,网格线绑定到主要或次要tic,并覆盖整个图形.
但是您可以绘制一些with vectors
.
As @Ethan already pointed out, gridlines are bound to major or minor tics and span the whole graph.
But you can plot something with vectors
.
顺便说一句,请注意您的代码
By the way, note that with your code
set table $Dummy
plot FILE u ($0==1?(Ymin=$1,Ymax=$2):NaN,Xmax=$8) w table
unset table
Ymin
和Ymax
将是 last 数据集的第二行(行)的第一列和第二列的值.如果您的数据没有空行,那么最后一个数据集也是第一个. Xmax
将是第8列的整体最后一个值.
Ymin
and Ymax
will be the values of of the first and second column of the second line(row) of the last dataset. If your data has no empty lines then the last dataset is also the first. Xmax
will be the overall last value of the 8th column.
对于您的任务,以下是一种解决方案.不需要sed或awk等. 由于我没有从您那里得到的示例数据,因此我假设有一点.
For you task, one solution could be the following below. No need for sed or awk, etc. Since I don't have example data from you I assume something.
- 从一个数据文件中获取网格线"的x位置
- 从另一个数据文件中提取
Ymin,Ymax,Xmax
- 绘制数据
with linespoints
和网格线"with vectors
- get the x positions for your "grid lines" from one datafile
- extract
Ymin,Ymax,Xmax
from another datafile - plot your data
with linespoints
and the "grid lines"with vectors
请注意,在较早的gnuplot版本中,strcol()
的限制为(我猜)为63个字符.使用gnuplot 5.2.7时,此问题已修复.
Note that in earlier gnuplot versions there was a limitation of strcol()
to (I guess) 63 characters. With gnuplot 5.2.7 this has been fixed.
代码:
### 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
结果:
添加:
上面,我向您展示了如何使用gnuplot提取必要的值. 是的,这不是那么容易理解,不是最短的方法,但这只是 gnuplot !如果您喜欢使用sed,awk等工具,但我无能为力.
Above I've shown you how to extract the necessary values with gnuplot. Yes, that's not so easy to understand and not the shortest way, but it's gnuplot only! If you prefer to use sed, awk or the like feel free, but there I cannot help.
另一种代替绘制矢量的方法是绘制箭头.假设您已经将数据包含在变量中.
Another approach instead of plotting vectors is drawing arrows. The assumption is that you have your data in your variables already.
代码:
### 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中设置网格线(矢量或箭头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!