Skip to content

Commit 3af71a8

Browse files
Merge pull request #237 from teddyrowan/master
Added lightweight title option
2 parents 278e4b4 + f5c1338 commit 3af71a8

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 7, 'alpha', 0)
2+
version_info = (0, 12, 7, 'alpha', 1)
33

44
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
55

src/mplfinance/plotting.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _valid_plot_kwargs():
148148
'Validator' : lambda value: mcolors.is_color_like(value) },
149149

150150
'title' : { 'Default' : None, # Figure Title
151-
'Validator' : lambda value: isinstance(value,str) },
151+
'Validator' : lambda value: isinstance(value,(str,dict)) },
152152

153153
'axtitle' : { 'Default' : None, # Axes Title (subplot title)
154154
'Validator' : lambda value: isinstance(value,str) },
@@ -624,16 +624,28 @@ def plot( data, **kwargs ):
624624
if external_axes_mode:
625625
volumeAxes.tick_params(axis='x',rotation=xrotation)
626626
volumeAxes.xaxis.set_major_formatter(formatter)
627-
627+
628628
if config['title'] is not None:
629629
if config['tight_layout']:
630630
# IMPORTANT: 0.89 is based on the top of the top panel
631631
# being at 0.18+0.7 = 0.88. See _panels.py
632632
# If the value changes there, then it needs to change here.
633-
fig.suptitle(config['title'],size='x-large',weight='semibold', va='bottom', y=0.89)
633+
title_kwargs = dict(size='x-large',weight='semibold', va='bottom', y=0.89)
634634
else:
635-
fig.suptitle(config['title'],size='x-large',weight='semibold', va='center')
636-
635+
title_kwargs = dict(size='x-large',weight='semibold', va='center')
636+
if isinstance(config['title'],dict):
637+
title_dict = config['title']
638+
if 'title' not in title_dict:
639+
raise ValueError('Must have "title" entry in title dict')
640+
else:
641+
title = title_dict['title']
642+
del title_dict['title']
643+
title_kwargs.update(title_dict) # allows override default values set by mplfinance above
644+
else:
645+
title = config['title'] # config['title'] is a string
646+
fig.suptitle(title,**title_kwargs)
647+
648+
637649
if config['axtitle'] is not None:
638650
axA1.set_title(config['axtitle'])
639651

0 commit comments

Comments
 (0)