如何绘制可变箭头和可变颜色?
有什么方法可以具有可变箭头和可变颜色?
我知道我可以用不同的头定义不同的箭头。 但是,如果我使用的是变量箭头,则无法设置可变颜色。 我会遇到一个错误:
在情节选项中重复或矛盾的论点
,例如附加LC RGB 0x123456
无法覆盖所选的箭头属性吗?太糟糕了。 因此,这是否意味着我必须为所有可能的箭头和所有可能的颜色的所有组合定义箭头? 另外,如果我只使用4个不同的箭头,则可以将箭头分成4个单独的绘图元素(带有许多不同的颜色)。 我看不到有更好的解决方案吗?我尝试了GNUPLOT 5.5。
脚本:
### how to plot variable arrowheads AND variable colors?
reset session
$Data <<EOD
1 -1 0x000000
2 0 0xff0000
3 1 0x00ff00
4 2 0x0000ff
5 1 0xff00ff
6 2 0xffff00
6 2 0x00ffff
EOD
set style arrow 1 backhead lw 3 # -1
set style arrow 2 nohead lw 3 # 0
set style arrow 3 head lw 3 # 1
set style arrow 4 heads lw 3 # 2
set key noautotitle
set offset 0.5,0.5,0.5,0.5
set multiplot layout 1,3
set title "variable arrowstyle"
plot $Data u (0):1:(2):(0):($2+2) w vectors as var
set title "variable color"
plot $Data u (0):1:(2):(0):3 w vectors lc rgb var lw 3
set title "variable arrowhead and color???"
plot $Data u (0):1:(2):(0):3 w vectors nohead lc "black" lw 1 dt 3
unset multiplot
### end of script
结果:
Is there any way to have variable arrowheads AND variable colors?
I know that I can define different arrowstyle with different heads.
However, if I am using variable arrowstyle I cannot set a variable color.
I will get an error:
duplicated or contradicting arguments in plot options
Apparently, e.g. an additional lc rgb 0x123456
can't overwrite the selected arrowstyle properties? Too bad.
So, would this mean I have to define arrowstyles for all combinations of possible arrowheads and all possible colors in advance?
Alternatively, if I use only 4 different arrowheads, I could split the arrowheads into 4 separate plot elements (with many different colors).
Are there better solutions which I don't see? I tried with gnuplot 5.5.
Script:
### how to plot variable arrowheads AND variable colors?
reset session
$Data <<EOD
1 -1 0x000000
2 0 0xff0000
3 1 0x00ff00
4 2 0x0000ff
5 1 0xff00ff
6 2 0xffff00
6 2 0x00ffff
EOD
set style arrow 1 backhead lw 3 # -1
set style arrow 2 nohead lw 3 # 0
set style arrow 3 head lw 3 # 1
set style arrow 4 heads lw 3 # 2
set key noautotitle
set offset 0.5,0.5,0.5,0.5
set multiplot layout 1,3
set title "variable arrowstyle"
plot $Data u (0):1:(2):(0):($2+2) w vectors as var
set title "variable color"
plot $Data u (0):1:(2):(0):3 w vectors lc rgb var lw 3
set title "variable arrowhead and color???"
plot $Data u (0):1:(2):(0):3 w vectors nohead lc "black" lw 1 dt 3
unset multiplot
### end of script
Result:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想出了如此出色的角落案例!我喜欢它。
这样做的预期方法是在箭头样式本身中设置
LC RGB变量
lc变量。我说“ 预期的方式”,因为事实证明这在实践中并不完全有效。它需要在
中使用
指定器中的6列:xy dx dy arrowstyle rgbcolor
,但该程序认为此绘图样式的最大可能性为5,并且给出了错误消息对于此样式使用规格太多
。这应该很容易解决,因此请尽快寻找开发版本的更新。
更新(2022年5月21日)
现在在上游修复了。该代码将在版本5.4.4中起作用。
You come up with such great corner cases! I love it.
The intended way to do this is to set
lc rgb variable
orlc variable
in the arrow style itself.I say "the intended way" because it turns out this doesn't quite work in practice. It requires 6 columns in the
using
specifier:x y dx dy arrowstyle rgbcolor
but the program thinks that the maximum possible for this plot style is 5 and gives an error messageToo many using specs for this style
.That should be an easy fix, so look for an update to the development version soonish.
Update (21 May 2022)
Now fixed upstream. This code will work in release 5.4.4.
这是我在问题中提到的一种解决方案。基本上,它为4个不同的箭头绘制了四次数据,并且每次使用三元操作员和
nan
每次清除其他箭头的数据。也许有更好的解决方案?
脚本:
结果:
This is one solution which I mentioned in the question. Basically, it plots the data four times for 4 different arrowheads and each time blanking the data for the other arrowheads by using the ternary operator and
NaN
.Maybe there are better solutions?
Script:
Result: