Gnuplot can create candlestick charts out of the box. These charts are often used for graphing financial data, with the middle block representing the difference between the open and close, and the high and low represented with lines protruding from the top and bottom of this box. The bars are colored differently depending on if the security’s price increased or decreased over this period of time. In gnuplot, losses are represented with filled bars.

Creating the graph is relatively easy. First you need a data file. This can be in a number of formats, but the following format is fairly common:


Once you have your data file, creating the graph is as simple as:

plot '<data_file>' using 1:2:4:3:5 with candlesticks

The 1:2:4:3:5 is the field order for date, open, low, high and close prices in the file. If your file has data in a different order, you will need to rearrange these numbers.

The following is a complete working example. We have two files; bhp.dat which contains the price data for BHP on the Australian Stock Exchange, and candlestick.gnuplot which contains the gnuplot instructions.


# BHP (Australian Stock Exchange)
# Date,Open,High,Low,Close


set terminal pngcairo font "arial,10" size 500,500
set output 'candlestick.png'
set xdata time
set timefmt"%Y-%m-%d"
set xrange ["2013-02-14":"2013-02-27"]
set yrange [*:*]
set datafile separator ","
plot 'bhp.dat' using 1:2:4:3:5 notitle with candlesticks

With these files, we can generate the graph on the command line with:

$ gnuplot candlestick.gnuplot

Which will generate candlestick.png which will look like this:

candlestick chart created with gnuplot

  1. Shivanshu Goswami says:

    Thanks, this was very useful.

  2. Hi there. This is pretty much only web page to explain how to plot candle chart with gnuplot. Thanks very much.

  3. Hector says:


    Great tutorial! I modified your example with set terminal dumb, because I need to view over ssh. I can view the chart but it is plotted with star (*) character, which makes it difficult to read. I know that ASCII won’t look pretty but… is there any workaround to make this graph readable over ssh? Perhaps by changing the star (*) character to a more “viewable” one? If the latter, how can I change the character used for plotting? Thank you in advance for any hint or orientation.