I'm trying to create a candlestick graph using some data that I have stored in a CSV file and the mpl_finance
library:
The first five rows look like this:
Date Open High Low Close Volume
0 2017-08-24 04:00:00.000000 0.002890 0.002890 0.002670 0.002670 371.64
1 2017-08-24 04:05:00.000000 0.002669 0.002669 0.002669 0.002669 4.80
2 2017-08-24 04:10:00.000000 0.002600 0.002649 0.002600 0.002649 61.71
3 2017-08-24 04:15:00.000000 0.002640 0.002640 0.002640 0.002640 20.00
4 2017-08-24 04:20:00.000000 0.002620 0.002620 0.002600 0.002602 92.68
Below is the code I'm using:
import pandas as pd
import matplotlib.pyplot as plt
from mpl_finance import candlestick2_ochl
df = pd.read_csv("data.csv")
df["Date"] = pd.to_datetime(df["Date"])
candlestick2_ochl(ax = df["Date"],opens=df["Open"],closes=df["Close"],highs =df["High"],lows = df["Low"])
plt.show()
When I run this code I get the following error:
Traceback (most recent call last):
File "Untitled 5.py", line 16, in <module>
candlestick2_ochl(ax = df["Date"],opens=df["Open"],closes=df["Close"],highs =df["High"],lows = df["Low"])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mpl_finance.py", line 552, in candlestick2_ochl
alpha=alpha)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mpl_finance.py", line 633, in candlestick2_ohlc
ax.update_datalim(corners)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'update_datalim'
(PS: I've tried running the code without df["Date"] = pd.to_datetime(df["Date"])
but it output the same error)
Thank you very much for your help!