【问题标题】:Cannot get labels to color in GNUPlot无法在 GNUPlot 中为标签着色
【发布时间】:2021-03-19 03:20:33
【问题描述】:

我一直在处理这个文件的一些种类:

$DATA << EOD
0.910731391716549   0.0917930320554009  LABEL1  '#008000'
0.871162274545609   0.181191762678911   LABEL2  '#ffff00'
EOD
set key off
set border 3; set tics nomirror
set xrange [0:*]
plot "$DATA" using 1:2:3:4 with labels textcolor rgb variable

这是基于gnuplot scatter plot, labels with color

这应该是一个散点图,带有标签LABEL1LABEL2,但是当我运行 GNUPlot gnuplot 5.2 patchlevel 8 时,我得到了这个错误:

"/tmp/oBjdIStjpA" line 13: warning: Skipping data file with no valid points

plot "$DATA" using 1:2:3:4 with labels textcolor rgb variable
                                                             ^
"/tmp/oBjdIStjpA" line 13: x range is invalid

这个错误没有意义。

如果我将 plot 行更改为 plot "$DATA" using 1:2:3:4 with labels GNUPlot 可以工作,但没有我想要的颜色。

我没有使用与其他海报相同的颜色编码,而且我不知道如何转换为其他海报使用的任何十进制编码。

如何获得每个点的颜色?

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    检查help colorspec。那里说textcolor rgb variable 采用数值(不是文本)。

    因此,如果您将 '#008000''#ffff00' 更改为 0x0080000xffff00,它应该可以工作。

    加法:

    如果您不想更改原始数据,您只需定义一个将字符串转换为整数的函数。

    代码:

    ### string color variable to integer
    reset session
    
    $Data <<EOD
    1   1   Label1   '#ff0000'
    2   2   Label2   '#00ff00'
    3   3   Label3   '#0000ff'
    4   4   Label4   '#ff00ff'
    5   5   Label5   '#ffff00'
    6   6   Label6   '#00ffff'
    EOD
    
    unset key
    set xrange [0:7]
    set yrange [0:7]
    myColor(col) = int('0x'.strcol(col)[3:])
    
    plot $Data using 1:2:3:(myColor(4)) w labels tc rgb var font ",17"
    ### end of code
    

    结果:

    【讨论】:

    • 这真是很棒的代码,它也适用于splot,非常感谢!
    猜你喜欢
    • 2018-08-26
    • 2011-01-07
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    相关资源
    最近更新 更多