3

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

Christoph
  • 47,569
  • 8
  • 87
  • 187
Jen
  • 97
  • 2
  • 7

1 Answers1

7

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

Thor
  • 45,082
  • 11
  • 119
  • 130
Joce
  • 2,220
  • 15
  • 26
  • 1
    Nice +1. The second solution produces one label for each data point, this can be reduced by using [the every Nth function](https://groups.google.com/d/msg/comp.graphics.apps.gnuplot/M_ldKLSFXwg/FFeOPZ4MCccJ). – Thor Mar 16 '16 at 11:53
  • 1
    Well, that's a clean solution. Combined it with the every Nth function and it turned out perfect. Thanks @Joce and @Thor! – Jen Mar 16 '16 at 12:58
  • Thanks @Thor, that's a great improvement! – Joce Mar 17 '16 at 07:37