Reputation: 26068
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:
Upvotes: 2
Views: 162
Reputation: 15118
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.
Upvotes: 2
Reputation: 26068
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:
Upvotes: 0