2013-11-27 25 views
6

我有3列的文件,第2的位置XY和第三一個我用它來定義顏色,所以我有這樣的事情:定製圖例(或文本)的gnuplot

set palette model RGB defined (1 'black', 2 'blue', 3 'green', 4 'red') 
unset colorbox 

plot "file" u 2:1:3 w points pt 14 ps 2 palette, "file2" u 2:1:3 w points pt 14 ps 2  palette 

現在的問題是:是否有可能通過這種觀點和COLOR有一個適當的傳說? 由於點將有不同的顏色(根據調色板),我想指定圖例中每種顏色的含義。

我想唯一的解決辦法是什麼地方寫的情節一些文字與點(在這種情況下,PT 14)的字符並指定顏色...但不是一個真正的解決辦法嗎?

所以,請大家幫忙!

+0

通常'colorbox',你不設置,是爲這個。 – Christoph

+0

你是什麼意思?我根本不是專家=) – Nikko

+0

從您的腳本中刪除'unset colorbox'部分,您將獲得顏色關聯值<->。或者你只有幾個顏色值,每種顏色都有不同的含義? – Christoph

回答

6

有這個沒辦法,你需要擺弄了一下。這裏是YAGH(另一個gnuplot破解);)

假設您的值是等距分隔的,您可以使用'+'特殊文件名和labels繪圖樣式。

只顯示自定義鍵,請看下面的例子:

labels="first second third fourth" 
set xrange[0:1] # must be set for '+' 
set yrange[0:1] 
set samples words(labels) # number of colors to use 
key_x = 0.8  # x-value of the points, must be given in units of the x-axis 
key_y = 0.8 
key_dy = 0.05 
set palette model RGB defined (1 'black', 2 'blue', 3 'green', 4 'red') 
unset colorbox 
plot '+' using (key_x):(key_y + $0*key_dy):(word(labels, int($0+1))):0 \ 
    with labels left offset 1,-0.1 point pt 7 palette t '' 

這給(與4.6.4):

enter image description here

由於set samples不影響數據圖,您可以在繪圖命令直接集成這樣的:

... 
unset key 
plot "file" u 2:1:3 w points pt 14 ps 2 palette, \ 
    "file2" u 2:1:3 w points pt 14 ps 2 palette, \ 
    '+' using (key_x):(key_y - $0*key_dy):(word(labels, int($0+1))):0 \ 
     with labels left offset 1,-0.1 point pt 14 ps 2 palette 

但是你需要設置一個適當的xrange,yrange和key_xkey_ykey_dy值。

這還不是最直觀的方式,但它的工作原理:)

+0

謝謝,非常有用。我調整了一點點是關乎更加動態縮放軸: key_x = x_range - x_range/10.0等...... –

1

我有一個替代的解決方案張貼在這裏: Using Gnuplot to plot point colors conditionally

基本上你繪製一次沒有圖例項,然後進行虛擬地塊(與沒有數據)爲每個點顏色/標籤。

+0

是的,迭代組合和'LC調色板frac'它應該很好地工作:'標籤=」 A B C D」; (NaN):(NaN)wp pt 14 ps 2 lc調色板壓縮(i/3.0)標題詞'plot'u 2:1:3 wp pt 14 ps 2 palette,for [i = 1:4] (ⅰ)'。 – Christoph