How Can I Customize Mplfinance.plot?
Solution 1:
The best way to do this is to define your own style using mpf.make_mpf_style()
rather than using the default mpf styles.
If using external axes method in mplfinance, you can plot multiple charts as below:
# add your own style by passing in kwargs
s = mpf.make_mpf_style(base_mpf_style='charles', rc={'font.size': 6})
fig = mpf.figure(figsize=(10, 7), style=s) # pass in the self defined style to the whole canvas
ax = fig.add_subplot(2,1,1) # main candle stick chart subplot, you can also pass in the self defined style here only for this subplot
av = fig.add_subplot(2,1,2, sharex=ax) # volume chart subplot
mpf.plot(price_data, type='candle', ax=ax, volume=av)
The default mpf styles are as below. I believe 'mike' and 'nighclouds' have dark background, not 100% sure about others, you can choose to work on top of these two.
In [5]:
mpf.available_styles()
Out[5]:
['binance',
'blueskies',
'brasil',
'charles',
'checkers',
'classic',
'default',
'mike',
'nightclouds',
'sas',
'starsandstripes',
'yahoo']
Link to visualize the default mplfinance styles
The arguments that can be passed in mpf.make_mpf_style()
are as below, you can use base_mpf_style, facecolor, gridcolor, gridstyle, gridaxis, rc
to customise your own style, and give it a name by using style_name
. You can play around with these arguments to see how they turn out.
def_valid_make_mpf_style_kwargs():
vkwargs = {
'base_mpf_style': { 'Default' : None,
'Validator' : lambda value: value in _styles.keys() },
'base_mpl_style': { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) }, # and is in plt.style.available'marketcolors' : { 'Default' : None, # 'Validator' : lambda value: isinstance(value,dict) },
'mavcolors' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,list) }, # TODO: all([mcolors.is_color_like(v) for v in value.values()])'facecolor' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) },
'edgecolor' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) },
'figcolor' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) },
'gridcolor' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) },
'gridstyle' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) },
'gridaxis' : { 'Default' : None,
'Validator' : lambda value: value in [ 'vertical'[0:len(value)], 'horizontal'[0:len(value)], 'both'[0:len(value)] ] },
'y_on_right' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,bool) },
'rc' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,dict) },
'style_name' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,str) },
}
_validate_vkwargs_dict(vkwargs)
return vkwargs
Solution 2:
To hide axes add this:
axisoff=True
Solution 3:
First you should upgrade your package to the latest version, then in your code, you can write: mpf.plot(......, axisoff= True) in my experience sometimes when using "axisoff= True", it is usefull to use figscale to obtain better results.
Post a Comment for "How Can I Customize Mplfinance.plot?"