Skip to content

Commit ef86bb3

Browse files
implement alias plot types
1 parent 14b0619 commit ef86bb3

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/mplfinance/_arg_validators.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ def _check_and_prepare_data(data, config):
6060

6161
return dates, opens, highs, lows, closes, volumes
6262

63+
def _get_valid_plot_types(plottype=None):
64+
65+
_alias_types = {
66+
'candlestick' : 'candle',
67+
'ohlc_bars' : 'ohlc',
68+
'hollow_candle' : 'hollow_and_filled',
69+
'hollow' : 'hollow_and_filled',
70+
'hnf' : 'hollow_and_filled',
71+
}
72+
73+
_valid_types = ['candle','ohlc', 'line','renko','pnf','hollow_and_filled']
74+
75+
_valid_types_all = _valid_types.copy()
76+
_valid_types_all.extend(_alias_types.keys())
77+
78+
if plottype is None:
79+
return _valid_types_all
80+
81+
if plottype not in _valid_types_all:
82+
return None
83+
elif plottype in _alias_types:
84+
return _alias_types[plottype]
85+
else:
86+
return plottype
87+
6388

6489
def _mav_validator(mav_value):
6590
'''

src/mplfinance/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volume
6868
collections = _construct_candlestick_collections(xdates, opens, highs, lows, closes,
6969
marketcolors=style['marketcolors'],config=config )
7070

71-
elif ptype =='hollow_candle':
71+
elif ptype =='hollow_and_filled':
7272
collections = _construct_hollow_candlestick_collections(xdates, opens, highs, lows, closes,
7373
marketcolors=style['marketcolors'],config=config )
7474

src/mplfinance/plotting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from mplfinance import _styles
3131

3232
from mplfinance._arg_validators import _check_and_prepare_data, _mav_validator
33+
from mplfinance._arg_validators import _get_valid_plot_types
3334
from mplfinance._arg_validators import _process_kwargs, _validate_vkwargs_dict
3435
from mplfinance._arg_validators import _kwarg_not_implemented, _bypass_kwarg_validation
3536
from mplfinance._arg_validators import _hlines_validator, _vlines_validator
@@ -99,8 +100,7 @@ def _valid_plot_kwargs():
99100
and len(value) == 5
100101
and all(isinstance(c, str) for c in value) },
101102
'type' : { 'Default' : 'ohlc',
102-
'Validator' : lambda value: value in ('candle','candlestick','ohlc','ohlc_bars',
103-
'line','renko','pnf','hollow_candle') },
103+
'Validator' : lambda value: value in _get_valid_plot_types() },
104104

105105
'style' : { 'Default' : None,
106106
'Validator' : _styles._valid_mpf_style },
@@ -277,6 +277,9 @@ def plot( data, **kwargs ):
277277
"""
278278

279279
config = _process_kwargs(kwargs, _valid_plot_kwargs())
280+
281+
# translate alias types:
282+
config['type'] = _get_valid_plot_types(config['type'])
280283

281284
dates,opens,highs,lows,closes,volumes = _check_and_prepare_data(data, config)
282285

0 commit comments

Comments
 (0)