【问题标题】:Set variable textcolor and point color with labels style in gnuplot在 gnuplot 中使用标签样式设置变量 textcolor 和点颜色
【发布时间】:2013-08-21 21:49:51
【问题描述】:

how to set label and line the same color in gnuplot 相关-但不完全相同...使用此代码:

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"

set xrange [0:3]
set yrange [0:3]

# function to get style index for coloring:
getCol(x) = (x==0)?1:((x==1)?2:3);

plot \
  '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \
    lc variable notitle, \
  "" using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
    textcolor variable point linestyle 1 pointtype 7 lc variable \
    font ",6" offset character 1.0,character 1.0  notitle
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e

...我得到这个输出:

看起来一切都可以为impulses 着色-但是对于labels,该方法似乎有效-但好像颜色是从不同的索引中读取的?!

那么,如何使用与脉冲线相同的函数使点和标签具有相同的可变颜色?这是在 gnuplot 4.6 补丁级别 1...

【问题讨论】:

  • 这个问题在新发布的4.6 patchlevel 4中得到了修复。只需在绘图前添加set style increment user行,你就会得到预期的结果(与my answer相同)。跨度>

标签: gnuplot


【解决方案1】:

impulses 的颜色索引用于选择线型,而labels 使用线型。此行为仍然存在于当前的开发版本中。根据文档,labels 的行为是正确的。 help linecolor variable 说:“lc variable 告诉程序使用从输入数据的一列读取的值作为线型索引......可以使用 tc variable 类似地设置文本颜色”。错误、功能或错误的文档?

作为一种解决方法,您可以使用lc palette 和适当定义的palette

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"

set palette defined (1 "aquamarine", 2 "blue", 3 "coral")
unset colorbox
set xrange [0:3]
set yrange [0:3]

# function to get style index for coloring:
getCol(x) = (x==0)?1:((x==1)?2:3)

unset key
plot \
  '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses lc variable, \
  '' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
    tc palette point ls 1 pt 7 lc palette offset 1,1
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e

这给出了结果:

我希望解决方法也适用于您的实际情况。如果由于某种原因无法重新定义调色板,可以使用lc rgb variable,在这种情况下,最后一列必须是相应 rgb 颜色的整数表示:

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"

set xrange [0:3]
set yrange [0:3]

rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
rgb1 = rgb(2, 215, 245) # something like aquamarine
rgb2 = rgb(0, 0, 255)
rgb3 = rgb(245,140,2)
getCol(x) = (x==0)?rgb1:((x==1)?rgb2:rgb3)

unset key
plot \
  '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \
    lc rgb variable, \
  '' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
    tc rgb variable point ls 1 pt 7 lc rgb variable offset 1,1
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e

您可能只需要调整 rgb 值。

但是,我会在 gnuplot 邮件列表上提出这个讨论,看看这是否真的是一个错误,或者其他什么。

【讨论】:

  • 非常感谢@Christoph - 很好的回答;偶然地,我发现了同样的set palette/unset colorbox 解决方法,所以它也适用于我的测试用例。但是很高兴了解lc rgb variable 方法。再次感谢 - 干杯!
  • @sdaau 发现gnuplot 提供的所有不同可能性来做同样的事情:) 很高兴听到它对您有所帮助。
猜你喜欢
  • 2020-08-29
  • 1970-01-01
  • 2013-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多