Jen
Jen

Reputation: 97

Remove weekend gaps in gnuplot for candlestick chart

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

enter image description here

Upvotes: 3

Views: 886

Answers (1)

Joce
Joce

Reputation: 2332

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:

Candlestick graph with no weekend gaps

Upvotes: 7

Related Questions