绘图向量仅以gnuplot开头 [英] Plot vectors only head with gnuplot
问题描述
我只需要绘制向量头,而是使用以下内容
I need to plot only the vectors head, but using the following
plot 'plot.txt' u 1:2:($3*factor):($4*factor) w vector lc rgb 'black'
我获得了所有向量.我只想要头.
I obtain all the vectors. I only want the head.
所以我需要删除仅保留头部的向量的一部分.我该如何绘制?
so I need to delete a part of a vector mantaining only the head. How can I plot this?
谢谢.
推荐答案
通过@Christoph链接的答案确实包含关键成分:
The answer linked by @Christoph indeed contains the key ingredient:
您需要的正确命令是
fixed
,它仅允许绘制头部
The right command that you need is
fixed
which allows to plot only the head
但是,这里可能应该更具体一些.关键字fixed
本身不产生仅箭头".其主要目的是确保箭头的大小与向量的长度无关.因此,为了只产生一个带有箭头的箭头,可以仅将箭头的起点沿端点的方向移动,直到将其隐藏"在头部内部.这就是为什么此答案中最里面的右箭头似乎仅由其头部形成的原因-主体(线)为只是被头部遮盖".
However, one should be perhaps slightly more specific here. The keyword fixed
per se does not produce "head-only arrows". Its primary purpose is to guarantee that the size of the arrows is independent of the length of the vectors. So in order to produce an arrow with its head only, one might merely shift the starting point of the arrow in the direction of the end point until it is "hidden" inside of the head. That's why the right inner-most arrow in this answer appears to be formed by its head only - the body (line) is just "covered" by the head.
因此,为了在实践中做到这一点,可以按照以下步骤进行操作:
So in order to do this in practice, one might proceed as:
reset
set terminal pngcairo
set output 'fig.png'
$db <<EOF
0.0 0.0 1 1
3.0 0.0 -1 1
3.0 3.0 -1 -1
0.0 3.0 1 -1
EOF
set xr [0:3]
set yr [0:3]
set size square
set xtics 0,1,3 in
set ytics 0,1,3 in
set mxtics 2
set mytics 2
unset key
set style arrow 1 head filled size screen 0.05,45 fixed lc rgb 'royalblue'
set style arrow 2 head filled size screen 0.05,45 fixed lc rgb 'dark-spring-green'
factor=0.5
sigma=0.99
plot \
$db using 1:2:(factor*$3):(factor*$4) with vectors as 2,\
$db using ($1+sigma*$3):($2+sigma*$4):((1-sigma)*$3):((1-sigma)*$4) with vectors as 1
plot
语句的第一部分产生箭头(绿色),缩放比例为0.5.由于它们的长度仍然很大,因此它们与头部以及身体一起出现.在第二部分中,存在移位因子0<=sigma<=1
-语句($1+sigma*$3):($2+sigma*$4):((1-sigma)*$3):((1-sigma)*$4)
然后请求一个箭头,该箭头的端点与以前相同(例如,第一列和第三列的总和独立于sigma),但原点移位沿箭头方向(sigma=0
恢复原始箭头,sigma=1
将产生零长度箭头).因此,如果sigma
足够接近1
,则只有箭头可见:
The first part of the plot
statement produces arrows (green) scaled with factor 0.5. Since their length is still significant, they appear with head as well as with the body. In the second part, there is the shift factor 0<=sigma<=1
- the statement ($1+sigma*$3):($2+sigma*$4):((1-sigma)*$3):((1-sigma)*$4)
then requests an arrow with the same endpoint as before (for example, sum of the first and third columns is independent of sigma), but with shifted origin along the direction of the arrow (sigma=0
recovers original arrow, sigma=1
would produce zero-length arrow). Thus if sigma
is sufficiently close to 1
, only the arrow heads are visible:
这篇关于绘图向量仅以gnuplot开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!