Created
July 3, 2018 09:39
-
-
Save kittinan/e4825f36afda580d3546974e8e32d47f to your computer and use it in GitHub Desktop.
Matplotlib plot candle stick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
from mpl_finance import candlestick_ohlc | |
df = pd.read_csv('data.csv', parse_dates=True) | |
start = "2016-01-01" | |
end = "2016-03-31" | |
dfx = df[start:end] | |
dfx['daten'] = dfx.index.map(mdates.date2num) | |
ohlc = dfx[['daten','open','high','low','close', 'volume']] | |
fig = plt.figure(figsize=(15,8)) | |
ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1) | |
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1) | |
ax1.xaxis_date() | |
candlestick_ohlc(ax1, ohlc.values, width=.6, colorup='g') | |
ax2.fill_between(ohlc.daten, ohlc.volume.values, 0, label="Volume") | |
fig.autofmt_xdate() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment