Remove weekend gaps in gnuplot for candlestick chart

左心房为你撑大大i 提交于 2019-12-01 06:09:38

问题


I am trying to plot some financial candlestick charts with gnuplot. The problem is that there is no data during the weekends, and I don't want these gaps to be showed. Picture and code included below.

set datafile separator ","
set xdata time
set timefmt"%Y-%m-%d"
set xrange ["2015-10-22":"2016-02-06"]
set yrange [*:*]
set format x
plot 'head.dat' using 1:2:4:3:5 notitle with candlesticks


回答1:


As you have one entry per working day, instead of using the dates as abscissae you can use the line number:

plot 'head.dat' using 0:2:4:3:5 notitle with candlesticks

Then I guess you'll ask how to restore the dates on the x-axis. You can use xticslabel :

set xtics rotate 90
plot "head.dat" u 0:2:4:3:5:xticlabels(1) notitle with candlesticks

If you want to avoid having every label shown use this everyNth function posted by dir, e.g. every fifth label:

set datafile separator ","
everyNth(countColumn, labelColumnNum, N) = \
  ( (int(column(countColumn)) % N == 0) ? stringcolumn(labelColumnNum) : "" ) 
set xtics rotate 90
plot "head.dat" using 0:2:4:3:5:xticlabels(everyNth(0, 1, 5)) notitle with candlesticks

Results in:



来源:https://stackoverflow.com/questions/36030346/remove-weekend-gaps-in-gnuplot-for-candlestick-chart

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