gnuplot: yerrorbars with linecolor variable

怎甘沉沦 提交于 2019-12-24 01:58:21

问题


I want to draw yerrorbars with different colors. I am able to draw points with different colors using the following code:

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

But I am not sure how to extend this to yerrrorbars. When I try and use the following code, the errorbars are colored only with default color. How do I color the errorbars with a specific color?

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

I found a way to do this by separating the data and then plotting it. But if there is a way without separating the data it would be a nicer solution.

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

回答1:


"using" specifies which columns will be the input for the command. So since your third column is linecolor, and yerrorbars linecolor expects the fourth column to be the line color, you need to specify using 1:2:($1-$2):3. So, this is the corrected version of your example:

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



回答2:


The problem is, that the third column ($1 - $2) is used to plot the yerrorbar (the ydelta more specifically). The documentation:

3 columns:  x  y  ydelta

You'll need to add another column for the linecolor. If you want to make up something fancy, you could do something like:

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

(e.g. use the integer part of the first column and add 1).

Or you can also use ternary operators if you want to choose between two colors:

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

(e.g. choose linecolor 1 if the value in the first column is greater than 1, linecolor 3 otherwise)



来源:https://stackoverflow.com/questions/9172219/gnuplot-yerrorbars-with-linecolor-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!