2012-02-07 44 views
1

我想繪製yerrorbars不同的顏色。我能夠用下面的代碼不同的顏色畫點:gnuplot:與linecolor變量的yerrorbars

reset 
plot "-" using 1:2:3 with points linecolor variable 
# x y linecolor 
-4.0 -3.8 1 
-3.0 -2.9 1 
-2.0 -2.1 2 
-1.0 -1.2 1 
1.0 1.1 1 
2.0 2.2 2 
3.0 3.3 3 
4.0 4.5 3 
end 

但我不知道如何將其擴展到yerrrorbars。當我嘗試使用以下代碼時,錯誤欄僅使用默認顏色着色。如何使用特定顏色爲錯誤欄添加顏色?

reset 
plot "-" using 1:2:($1-$2) with yerrorbars linecolor variable 
# x y linecolor 
-4.0 -3.8 1 
-3.0 -2.9 1 
-2.0 -2.1 2 
-1.0 -1.2 1 
1.0 1.1 1 
2.0 2.2 2 
3.0 3.3 3 
4.0 4.5 3 
end 

我找到了一種方法來分離數據然後繪製它。但是如果沒有分離數據的方式,這將是一個更好的解決方案。

reset 
plot "-" using 1:2:($1-$2) with yerrorbars lc 1, \ 
    "-" using 1:2:($1-$2) with yerrorbars lc 2, \ 
    "-" using 1:2:($1-$2) with yerrorbars lc 3 

# x  y 
-4.0 -3.8 
-3.0 -2.9 
-1.0 -1.2 
1.0 1.1 
end 

-2.0 -2.1 
2.0 2.2 
end 

3.0 3.3 
4.0 4.5 
end 

回答

0

的問題是,該第三列($1 - $2)用於繪製yerrorbar(所述ydelta更具體)。文檔:

3 columns: x y ydelta 

需要添加另一列爲linecolor。如果你想彌補花哨的東西,你可以這樣做:

plot "/tmp/test.foo" using 1:2:($1-$2):(int($1)+1) with yerrorbars linecolor variable 

(例如使用第一列的整數部分,並添加1)。

或者,如果你想在兩種顏色之間選擇,你還可以使用三元運算符:

plot "-" using 1:2:($1 > 1 ? 1 : 3) with yerrorbars linecolor variable 

(如選擇linecolor 1,如果第一列中的值大於1,linecolor 3否則)

2

「using」指定哪些列將作爲命令的輸入。因此,由於第三列是linecolor,yerrorbars linecolor期望第四列是行顏色,所以您需要指定使用1:2:($ 1- $ 2):3。所以,這是你的例子的修正版本:

reset 
plot "-" using 1:2:($1-$2):3 with yerrorbars linecolor variable 
# x y linecolor 
-4.0 -3.8 1 
-3.0 -2.9 1 
-2.0 -2.1 2 
-1.0 -1.2 1 
1.0 1.1 1 
2.0 2.2 2 
3.0 3.3 3 
4.0 4.5 3 
end