Gnuplot 烛台和箱宽

标签 gnuplot financial candlestick-chart

一直在使用烛台来处理真实的财务数据。除非我的数据存在缺口,否则它的效果很好,而历史财务数据中有很多这样的缺口。

我已经“set boxwidth 1relative”并且它工作正常,在大多数情况下它给了我一个合适的烛台“宽度”。但如果两点之间没有数据,烛台就会变得更粗,即它会向右延伸以填补该缺口。视觉效果很糟糕,向右延伸真的很糟糕。

我尝试过设置 boxwidth x 绝对值,但我无法确定它的显示方式。我已将其范围缩小到 set boxwidth 37500 Absolute 并且不知道为什么这个数字有效,尽管它的问题比 set boxwidth 1relative 更糟糕。

第一张图片是使用 set boxwidth 37500 Absolute 的效果。日期为 01/31/13、02/01/13、02/03/13、02/04/13、02/05/13。没有 2013 年 2 月 2 日:

enter image description here

绝对值显示 02/01 和 02/02 之间有适当的差距,但 02/03 和 02/04 重叠,原因我无法解释。

第二张图片使用 set boxwidth 1relative。这基本上就是我想要的。烛台相邻且大部分位于右侧。但 2013 年 2 月 2 日的差距向右变大。在 2013 年 2 月 9 日也有一个间隙,它也会变胖,或者可能是两侧的 2 延伸以填补我不知道的间隙。

enter image description here

我该如何配置才能使所有烛台相邻宽度相同并且数据中的间隙为空?

我疯狂地用谷歌搜索了这个问题,但没有人谈论它。我发现的几个烛台示例不使用“日期”,而是使用整数,完全毫无值(value)。烛台图需要根据手册提供日期。

在 Windows 7 上运行 Gnuplot 4.6 补丁级别 0。

谢谢

PS:我应该在这里添加数据。

basic.csv:

2013-01-15 00:00:00,93.879000,93.949000,92.874000,93.078000
2013-01-16 00:00:00,93.079000,93.672000,92.458000,92.800000
2013-01-17 00:00:00,92.799000,95.011000,92.629000,94.616000
2013-01-18 00:00:00,94.617000,94.872000,94.157000,94.662000
2013-01-20 17:00:00,94.649000,94.820000,93.965000,94.155000
2013-01-21 00:00:00,94.159000,94.938000,93.726000,94.009000
2013-01-22 00:00:00,94.011000,94.284000,93.147000,93.231000
2013-01-23 00:00:00,93.229000,94.024000,92.793000,93.649000
2013-01-24 00:00:00,93.650000,94.715000,93.559000,94.489000
2013-01-25 00:00:00,94.490000,95.083000,94.472000,94.749000
2013-01-27 17:00:00,94.819000,95.007000,94.652000,94.834000
2013-01-28 00:00:00,94.835000,94.968000,94.082000,94.809000
2013-01-29 00:00:00,94.803000,95.330000,94.370000,95.248000
2013-01-30 00:00:00,95.245000,95.450000,94.255000,94.365000
2013-01-31 00:00:00,94.372000,95.799000,94.328000,95.714000
2013-02-01 00:00:00,95.715000,96.718000,95.457000,96.597000
2013-02-03 17:00:00,96.716000,96.777000,96.370000,96.572000
2013-02-04 00:00:00,96.574000,97.064000,95.968000,96.044000
2013-02-05 00:00:00,96.043000,97.426000,95.945000,97.131000
2013-02-06 00:00:00,97.133000,97.284000,96.092000,96.395000
2013-02-07 00:00:00,96.396000,97.023000,95.813000,96.145000
2013-02-08 00:00:00,96.146000,96.182000,95.124000,95.625000
2013-02-10 17:00:00,95.623000,95.744000,95.210000,95.339000
2013-02-11 00:00:00,95.336000,96.877000,95.168000,96.537000
2013-02-12 00:00:00,96.536000,96.719000,95.776000,96.214000
2013-02-13 00:00:00,96.216000,96.890000,96.114000,96.775000
2013-02-14 00:00:00,96.771000,96.964000,95.609000,95.621000
2013-02-15 00:00:00,95.622000,96.676000,95.521000,96.351000

absolute.plt:

reset

set border linecolor rgbcolor "yellow"
set key textcolor rgbcolor "white"

set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2013-01-15 00:00:00":"2013-02-15 23:59:59"]

set yrange [*:*]
set datafile separator ","

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

set style fill solid noborder
set boxwidth 37500 absolute

set title "AUDJPY" textcolor rgbcolor "white"
plot 'basic.csv' using 1:2:4:3:5:($5 < $2 ? -1 : 1) with candlesticks palette

relative.plt:

reset

set border linecolor rgbcolor "yellow"
set key textcolor rgbcolor "white"

set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2013-01-15 00:00:00":"2013-02-15 23:59:59"]

set yrange [*:*]
set datafile separator ","

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

set style fill solid noborder
set boxwidth 1 relative

set title "AUDJPY" textcolor rgbcolor "white"
plot 'basic.csv' using 1:2:4:3:5:($5 < $2 ? -1 : 1) with candlesticks palette

最佳答案

当使用set boxwidth Absolute时,宽度以x轴为单位给出,在日期的情况下为秒。因此,37500 的宽度是 10 小时。

您还可以在第 6 列中使用显式宽度,并切换到 -2 以获得某些列的自动框宽度。然而,这需要您手动操作数据文件。

另一点:您是否有必要在某些数据点中包含时间?这就是缩小一些相邻点的距离的原因。您可以忽略时间,这将为您提供至少一天的点距离。要去除小时数,请在 using 语句中使用 strptime:

reset

set border linecolor rgbcolor "yellow"
set key textcolor rgbcolor "white"

set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"

set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2013-01-15 00:00:00":"2013-02-15 23:59:59"]

set yrange [*:*]
set datafile separator ","

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

set style fill solid noborder
set boxwidth 60000 absolute

set title "AUDJPY" textcolor rgbcolor "white"
plot 'basic.csv' using (strptime('%Y-%m-%d', strcol(1))):2:4:3:5:($5 < $2 ? -1 : 1) with candlesticks palette

4.6.0 的结果:

enter image description here

关于Gnuplot 烛台和箱宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24092212/

相关文章:

python - 如何制作基于文本的界面(TUI/TLI)来监控 OpenFOAM 求解器日志文件?

variables - 计算由 Gnuplot 中的变量给出的列的值

date - gnuplot xtic 标签与日期的位置错误

.net - .NET 中计费/发票软件设计的最佳实践

r - adjustOHLC - 需要解决方案来循环股票的字符向量

python - 在同一 qtchart 上绘制烛台和 5 天平均线,但给出两个 x 轴图

bash - 直接使用 gnuplot 完成绘图并使用管道输入数据

Windows 窗体的 C# 金融图表库?

datetime - 无法使用日期/时间字段在 Gnuplot 中绘制烛台数据

python - 烛台图表不显示 plotly