gnuplot:应用数据文件中的颜色名称 [英] gnuplot: apply colornames from datafile

查看:93
本文介绍了gnuplot:应用数据文件中的颜色名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从数据文件中获取颜色名称?
我没想到这会这么困难,但显然是这样。
为什么版本1和版本2给出错误的颜色?有没有更简单的方法来获得正确的颜色而不使用版本3中的数组?并且 ... lc var 仅适用于索引值,而不适用于颜色名称。

How can I take colornames from a datafile? I didn't expect this to be so difficult, but apparently it is. Why do version 1 and version 2 give wrong colors? Is there a simpler way to achieve correct colors without using arrays as in version 3? And ...lc var only works with index values but not with colornames.

### colornames from data
reset session

$Data <<EOD
1   40  orange
2   35  cyan
3   25  red
4   15  yellow
5   5   green
EOD

set yrange [0:]
set multiplot layout 3,1
MyColor = "black"
plot \
    $Data u 1:(MyColor=strcol(3),$2):(0.7) w boxes fs solid 1.0 lc rgb MyColor notitle,\
    $Data u 1:($2/2):(strcol(3)) with labels tc rgb "white" notitle

plot \
    for [i=1:|$Data|] $Data u (MyColor=strcol(3),$1):2:(0.7) every ::i-1::i-1 w boxes fs solid 1.0 lc rgb MyColor notitle,\
    $Data u 1:($2/2):(strcol(3)) with labels notitle

array MyColors[|$Data|]
plot \
    $Data u (NaN):(MyColors[$0+1]=strcol(3)) notitle,\
    for [i=1:|$Data|] $Data u 1:2:(0.7) every ::i-1::i-1 w boxes fs solid 1.0 lc rgb MyColors[i] notitle,\
    $Data u 1:($2/2):(strcol(3)) with labels notitle

print MyColors
unset multiplot
### end of code

推荐答案

这是通过使用从数据文件或数据块自动生成的调色板进行的另一种方法。
这样,您不必关心十六进制数字或任何数字或颜色代码。
您只需要确保您没有使用无效的颜色名称即可。除非长数据集的调色板长度受到限制,否则此方法应该起作用。

Here is another approach by using an autmatically generated palette from your datafile or datablock. With this you don't have to care about the Hex-numbers or any number or codes of colors. You only need to make sure that you are not using invalid color names. This should work unless there is a limitation on the length of the color palette for long datasets.

### colornames from data
reset session

$Data <<EOD
1   40  red
2   35  orange
3   25  yellow
4   20  greenyellow
5   15  web-green
6   12  web-blue
7   10  violet
EOD

MyPalette = '('
set table $Dummy
    plot $Data u (MyPalette = MyPalette.sprintf('%d "%s", ',$0,strcol(3))) with table
unset table
MyPalette = MyPalette[:strlen(MyPalette)-2].')'
set palette model RGB defined @MyPalette
unset colorbox 

set yrange[0:]
plot $Data u 1:2:(0.7):0 w boxes fs solid 1.0 lc palette notitle,\
    '' u 1:($2/2):(strcol(3)) with labels notitle
### end of code

这篇关于gnuplot:应用数据文件中的颜色名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆