Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added markevery feature to plotting.py #569

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def _valid_plot_kwargs():
'type' : { 'Default' : 'ohlc',
'Description' : 'Plot type: '+str(_get_valid_plot_types()),
'Validator' : lambda value: value in _get_valid_plot_types() },
'markevery' : { 'Default' : None,
'Description' : 'markevery: size color shape ',
'Validator' : lambda value: isinstance(value,(tuple, list, int))},


'style' : { 'Default' : None,
'Description' : 'plot style; see `mpf.available_styles()`',
Expand Down Expand Up @@ -407,7 +411,8 @@ def plot( data, **kwargs ):
moving averages, renko, etc.
Also provide ability to plot trading signals, and/or addtional user-defined data.
"""

import sys
sys.stdout = sys.__stdout__
config = _process_kwargs(kwargs, _valid_plot_kwargs())

# translate alias types:
Expand Down Expand Up @@ -492,6 +497,7 @@ def plot( data, **kwargs ):
else:
panels = _build_panels(fig, config)
axA1 = panels.at[config['main_panel'],'axes'][0]
warnings.warn(f"this type is {type(axA1)}")
if config['volume']:
if config['volume_panel'] == config['main_panel']:
# ohlc and volume on same panel: move volume to secondary axes:
Expand Down Expand Up @@ -525,10 +531,10 @@ def plot( data, **kwargs ):
collections = None
if ptype == 'line':
lw = config['_width_config']['line_width']
axA1.plot(xdates, closes, color=config['linecolor'], linewidth=lw)
pmarkevery = config['markevery']
axA1.plot(xdates, closes, 'o', markevery=pmarkevery, ls='-', color=config['linecolor'], linewidth=lw, )
else:
collections =_construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style)

if ptype in VALID_PMOVE_TYPES:
collections, calculated_values = collections
volumes = calculated_values['volumes']
Expand Down Expand Up @@ -650,10 +656,35 @@ def plot( data, **kwargs ):
tlines = [tlines,]
for tline_item in tlines:
line_collections.append(_construct_tline_collections(tline_item, dtix, dates, opens, highs, lows, closes))

for collection in line_collections:
if collection is not None:
axA1.add_collection(collection)
### note
# if config['addplot'] is not None:
# for panid,row in panels.iterrows():
# print(panid)
# print("the value of min and max is ",miny,maxy)
# print("type of row is ", type(row))
# print("panid is ",panid)
# print("row key is ",row.keys())
# ax = row['axes']
# line_collections = []
# if (panid == 0):
# line_collections.append(_construct_vline_collections(config['vlines'], dtix, miny, maxy))
# else:
# line_collections.append(_construct_vline_collections(config['vlines'], dtix, 200, 600))

# for collection in line_collections:
# if collection is not None:
# ax[0].add_collection(collection)
if config['addplot'] is not None:
for panid,row in panels.iterrows():
ax = row['axes']
print(dtix)
print(config['vlines'])
# _date_to_iloc
ax[0].axvline(x=50.5,linestyle='--')
else:
for collection in line_collections:
if collection is not None:
axA1.add_collection(collection)

datalen = len(xdates)
if config['volume']:
Expand Down
9 changes: 9 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pandas as pd
import mplfinance as mpf
df = pd.read_csv('data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)

apdict = [mpf.make_addplot(df['LowerB']),
mpf.make_addplot(df['UpperB'],panel=1)]
vls = pd.date_range(df.index.min(), df.index.max(), freq='D').tolist()
kwargs = dict(type='candle', vlines=dict(vlines=vls[0], linewidths=0.5, colors=('r')))
mpf.plot(df,volume=False,addplot=apdict,**kwargs)