gnuplot烛台红色和绿色填充

时间:2014-04-24 13:46:30

标签: gnuplot candlestick-chart

金融网站上的烛台图,至少是我看过的那些,如果收盘价高于开盘价,则将烛台填充为绿色;如果收盘价低于开盘价,则为红色。

如果我设置填充样式,所有烛台都填充了填充颜色,gnuplot 4.6中是否有一种方法可以使用上面描述的颜色方案?

示例脚本是:

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2014-01-01":"2014-01-02"]
set yrange [*:*]
set datafile separator ","
plot '201401_EURUSD_Hourly.csv' using 1:2:4:3:5 notitle with candlesticks

有一些数据点

2014-01-01 17:00:00,1.376150,1.376550,1.374020,1.375990
2014-01-01 18:00:00,1.376100,1.377340,1.375980,1.376520 
2014-01-01 19:00:00,1.376440,1.376870,1.375780,1.375860 
2014-01-01 20:00:00,1.375850,1.376470,1.375000,1.376280 
2014-01-01 21:00:00,1.376270,1.376720,1.375970,1.376530 
2014-01-01 22:00:00,1.376550,1.377440,1.376270,1.376530 
2014-01-01 23:00:00,1.376540,1.376540,1.374390,1.374520 
2014-01-02 00:00:00,1.374500,1.375790,1.374380,1.375660 
2014-01-02 01:00:00,1.375630,1.375740,1.374610,1.375000 
2014-01-02 02:00:00,1.374980,1.375270,1.372480,1.373100

1 个答案:

答案 0 :(得分:4)

以下是使用预定义调色板选择颜色(关键字palette)的示例:

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set datafile separator ","

set palette defined (-1 'red', 1 'green')
set cbrange [-1:1]
unset colorbox

set style fill solid noborder

plot '201404_EURUSD_Hourly.csv' using 1:2:4:3:5:($5 < $2 ? -1 : 1)  notitle with candlesticks palette

使用额外的列(最后一列)在值-1(红色,低于开放)和+1(绿色,高于开放)之间进行选择。

4.6.4的输出是:

enter image description here

第二个选项是使用linecolor rgb variable,在这种情况下,最后一列必须是rgb-tuple的整数表示形式:

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set datafile separator ","

set style fill solid noborder

# Place colored points in 3D at the x,y,z coordinates corresponding to
# their red, green, and blue components
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)

plot '201404_EURUSD_Hourly.csv' using 1:2:4:3:5:($5 < $2 ? rgb(255,0,0) : rgb(0,255,0))  linecolor rgb variable notitle with candlesticks

最后但并非最不重要的是,使用linecolor variable在两种线型之间进行选择(最后一列是线型索引):

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set datafile separator ","

set style fill solid noborder

set linetype 1 lc rgb 'red'
set linetype 2 lc rgb 'green'

plot '201404_EURUSD_Hourly.csv' using 1:2:4:3:5:($5 < $2 ? 1 : 2)  linecolor variable notitle with candlesticks