如何绘制可变箭头和可变颜色?

发布于 2025-01-30 12:19:54 字数 1389 浏览 4 评论 0原文

有什么方法可以具有可变箭头和可变颜色?

我知道我可以用不同的头定义不同的箭头。 但是,如果我使用的是变量箭头,则无法设置可变颜色。 我会遇到一个错误:

在情节选项中重复或矛盾的论点

,例如附加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:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稍尽春風 2025-02-06 12:19:54

您想出了如此出色的角落案例!我喜欢它。
这样做的预期方法是在箭头样式本身中设置LC RGB变量 lc变量。

set style arrow 1 backhead lw 3 lc rgb variable
set style arrow 2 nohead   lw 3 lc rgb variable
set style arrow 3 head     lw 3 lc rgb variable
set style arrow 4 heads    lw 3 lc rgb variable

set title "variable arrowhead and color"
plot $Data u (0):1:(2):(0):($0+1):3 w vectors as variable

我说“ 预期的方式”,因为事实证明这在实践中并不完全有效。它需要在中使用指定器中的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 or lc variable in the arrow style itself.

set style arrow 1 backhead lw 3 lc rgb variable
set style arrow 2 nohead   lw 3 lc rgb variable
set style arrow 3 head     lw 3 lc rgb variable
set style arrow 4 heads    lw 3 lc rgb variable

set title "variable arrowhead and color"
plot $Data u (0):1:(2):(0):($0+1):3 w vectors as variable

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 message Too 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.

掐死时间 2025-02-06 12:19:54

这是我在问题中提到的一种解决方案。基本上,它为4个不同的箭头绘制了四次数据,并且每次使用三元操作员和nan每次清除其他箭头的数据。

也许有更好的解决方案?

脚本:

### plotting 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):($2==-1?0:NaN):3 w vectors lc rgb var lw 2 backhead, \
            '' u (0):1:(2):($2== 0?0:NaN):3 w vectors lc rgb var lw 2 nohead, \
            '' u (0):1:(2):($2== 1?0:NaN):3 w vectors lc rgb var lw 2 head, \
            '' u (0):1:(2):($2== 2?0:NaN):3 w vectors lc rgb var lw 2 heads
unset multiplot
### end of script

结果:

”

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:

### plotting 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):($2==-1?0:NaN):3 w vectors lc rgb var lw 2 backhead, \
            '' u (0):1:(2):($2== 0?0:NaN):3 w vectors lc rgb var lw 2 nohead, \
            '' u (0):1:(2):($2== 1?0:NaN):3 w vectors lc rgb var lw 2 head, \
            '' u (0):1:(2):($2== 2?0:NaN):3 w vectors lc rgb var lw 2 heads
unset multiplot
### end of script

Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文