删除 gnuplot 中的 weekend/non-trading 小时间隔
Removing weekend/non-trading hours gaps in gnuplot
我的问题与 相同,只是我对烛台使用条件着色并且提到的解决方案不起作用。
我的数据是这样的:
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 : ( < ? rgb(255, 0, 0) : rgb(0, 255, 0)) linecolor rgb variable notitle with candlesticks
生成有间隙的图表。我希望 gnuplot 忽略间隙并连续绘制烛台。有没有办法做到这一点?
查看下面生成的虚拟数据示例。尽管图中的 xtics 看起来是等距的,但 xtics 的值根本不是等距的。因此,如果您想读出两个 xtics 之间的 y-value,您不会 "any" 知道实际的 x-value 是什么。您只知道它必须位于相邻 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([=10=])%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:(< ? 0xff0000 : 0x00ff00):xtic(everyNthRow(N)) w candlesticks lc rgb var not
### end of code
结果:
我的问题与
我的数据是这样的:
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 : ( < ? rgb(255, 0, 0) : rgb(0, 255, 0)) linecolor rgb variable notitle with candlesticks
生成有间隙的图表。我希望 gnuplot 忽略间隙并连续绘制烛台。有没有办法做到这一点?
查看下面生成的虚拟数据示例。尽管图中的 xtics 看起来是等距的,但 xtics 的值根本不是等距的。因此,如果您想读出两个 xtics 之间的 y-value,您不会 "any" 知道实际的 x-value 是什么。您只知道它必须位于相邻 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([=10=])%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:(< ? 0xff0000 : 0x00ff00):xtic(everyNthRow(N)) w candlesticks lc rgb var not
### end of code
结果: