簡體   English   中英

無法在 GNUPlot 中為標簽着色

[英]Cannot get labels to color in GNUPlot

我一直在處理這個文件的一些種類:

$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,帶有顏色的標簽

它應該制作一個散點圖,帶有標簽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

這個錯誤沒有意義。

如果我使用帶有標簽 GNUPlot 的 1:2:3:4 將plot行更改為plot "$DATA" using 1:2:3:4 with labels工作,但沒有我想要的 colors。

我沒有使用與另一張海報相同的顏色編碼,而且我不知道如何轉換為另一張海報使用的任何十進制編碼。

如何獲得每個點的 colors?

檢查help colorspec 那里說textcolor rgb variable采用數值(不是文本)。

因此,如果您將'#008000''#ffff00'更改為0x0080000xffff00它應該可以工作。

添加:

如果您不想更改原始數據,只需定義一個 function 即可將字符串轉換為 integer 數字。

代碼:

### 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

結果:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM