Search code examples
pythonmatplotlibcandlestick-chart

How can I make a candlestick chart from my own data


All of the examples I find online have to do with pulling data from the internet. I have my own data and I only want the max and min aspect of the candlestick (don't need beginning and ending levels on the candlesticks).

I have a list of decimal values:

values=[[5,6],[6,7],[7,8.8],...]

I have

from matplotlib.pyplot import subplots, draw
from matplotlib.finance import candlestick, candlestick2

fig, ax = subplots()
candlestick(ax, values, width=0.5)
plt.show()

I wrote this based on online examples. I am not sure what the ax means and how it is used. Also, I am not sure how to input the values list correctly. Right now I get the following error:

Traceback (most recent call last):
  File "algor.py", line 41, in <module>
    candlestick(ax, values, width=0.5)
  File "/usr/lib/pymodules/python2.7/matplotlib/finance.py", line 330, in candlestick
    t, open, close, high, low = q[:5]
ValueError: need more than 2 values to unpack

is it complaining because I have only 2 instead of 4 inputs? I only want a rectangles, without the tails. Should I change values to

values=[[5,5,6,6],[7,7,8.8,8.8],...]

edit: this gives me the same error


Solution

  • The quotes argument to candlestick must be a sequence of (time, open, close, high, low, ...) according to the documentation here. If you only want rectangles without tails, maybe you could use a box plot instead.