I would like to plot a line without using a "default ohlc data". In this case, I'm using the data in the Github.
How can I do this?
import pandas as pd
import mplfinance as mpf
import matplotlib.animation as animation
import numpy as np
path_ = 'C:\Mypath'
intraday = pd.read_csv(path_ 'SP500_NOV2019_IDay.csv',index_col=0,parse_dates=True)
intraday.index.name = 'Date'
# mpf.plot(intraday,type='line') #ohlc DataFrame.. ok
int_Low = intraday.loc[:,'Low'] #non ohlc DataFrame
mpf.plot(data=int_Low,type='line') #doesn't work
CodePudding user response:
It seems that mplfinance is designed around a base OHLC chart. One way to make a Low line is to add it to the chart:
lowline = mpf.make_addplot(intraday['Low'], type='line')
mpf.plot(intraday, addplot=lowline)
CodePudding user response:
Unfortunately, as mplfinance is now, when plotting type='line'
then mpf.plot(data,type='line')
will, by default, use the 'Close' column.
One possible work-around would be to put your 'Low' data into the 'Close' column.
df = pd.read_csv('examples/data/SP500_NOV2019_IDay.csv',index_col=0,parse_dates=True)
df['RealClose'] = df['Close'].values # save close values in case want them later
df['Close'] = df['Low'].values # set 'Close' column to low values
mpf.plot(df,type='line') # plot 'Low' as a line
Another solution might be to enhance mplfinance to accept a kwarg called use_column
. Then, for example, one could simply write:
df = pd.read_csv('examples/data/SP500_NOV2019_IDay.csv',index_col=0,parse_dates=True)
mpf.plot(df,type='line',use_column='Low')
This enhancement is relatively easy to implement (just a few lines of code). Please let me know, in a comment below, if you are interested in contributing to mplfinance. Full disclosure: I am the maintainer of mplfinance.