消除gnuplot中的周末/非交易时间差距

时间:2019-06-15 12:15:08

标签: plot gnuplot candlestick-chart

我的问题与this question相同,除了我对烛台使用条件着色并且提到的解决方案无效。

我的数据就像:

10/24/2018 23:45,168.25,168.65,168.2,168.4,0
10/24/2018 23:46,168.5,169,168.5,168.95,67577
10/24/2018 23:47,169.35,169.6,169.1,169.1,151630
10/24/2018 23:48,169.05,169.35,168.95,169.2,63418
.
.
10/26/2018 13:48,169.05,169.35,168.95,169.2,63418
10/26/2018 23:47,169.35,169.6,169.1,169.1,151630
10/26/2018 23:48,169.05,169.35,168.95,169.2,63418

使用以下命令在gnuplot中绘制这样的文件:

plot ".../ISTFeed.csv" using (timecolumn(1, "%m/%d/%Y %H:%M:%S")) : 2 : 3 : 4 : 5 : ($5 < $2 ? rgb(255, 0, 0) : rgb(0, 255, 0)) linecolor rgb variable notitle with candlesticks

产生带有间隙的图表。我希望gnuplot忽略间隙并连续绘制烛台。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

看看下面的示例,其中包含生成的伪数据。尽管图中的xtics等距,但xtics的值根本不是等距的。因此,如果您想在两个xtics之间读取y值,则您根本不知道“实际” x值是多少。您只知道它必须在相邻xtics之间。有点奇怪...但是如果您对此精度满意的话...

代码:

### remove gaps in timedata
# requires gnuplot >=5.2, because of use of datablocks
reset session

# generate some dummy data
t = strptime("%m/%d/%Y %H:%M", "10/24/2018 23:45")
close = 168.25
set print $Data
print "#      date time,    open,     low,    high,   close"
do for [i=1:100] {
    open = close + (rand(0)*2)-1
    low_tmp = open - rand(0)
    high_tmp = open + rand(0)
    close = open + (rand(0)*2)-1
    low = open<low_tmp ? open : close<low_tmp ? close : low_tmp
    high = open>high_tmp ? open : close>high_tmp ? close : high_tmp
    dt = 3600*rand(0)*48
    t = t + dt
    print sprintf("%s,%8 .2f,%8 .2f,%8 .2f,%8 .2f",strftime("%m/%d/%Y %H:%M",t),open,low,high,close)
}
set print
print $Data

N = 10
Offset = 5
everyNthRow(N) = (int($0)%N==Offset ? word(strcol(1),1) : NaN)
set datafile separator ","
set xtics rotate by 45 right
set style fill solid 1.0
plot $Data u 0:2:3:4:5:($5<$2 ? 0xff0000 : 0x00ff00):xtic(everyNthRow(N)) w candlesticks lc rgb var not

### end of code

结果:

enter image description here