Skip to content

Commit 1119898

Browse files
implement returnfig
1 parent 4126670 commit 1119898

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/mplfinance/plotting.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def _valid_plot_kwargs():
125125
'block' : { 'Default' : True,
126126
'Validator' : lambda value: isinstance(value,bool) },
127127

128+
'returnfig' : { 'Default' : False,
129+
'Validator' : lambda value: isinstance(value,bool) },
130+
128131
}
129132

130133
_validate_vkwargs_dict(vkwargs)
@@ -476,22 +479,29 @@ def plot( data, **kwargs ):
476479
if not used_ax4 and ax4 is not None:
477480
ax4.get_yaxis().set_visible(False)
478481

482+
if config['returnfig']:
483+
axlist = [ax1, ax3]
484+
if ax2: axlist.append(ax2)
485+
if ax4: axlist.append(ax4)
486+
479487
if config['savefig'] is not None:
480488
save = config['savefig']
481489
if isinstance(save,dict):
482490
plt.savefig(**save)
483491
else:
484492
plt.savefig(save)
485-
else:
493+
elif not config['returnfig']:
486494
# https://stackoverflow.com/a/13361748/1639359 suggests plt.show(block=False)
487495
plt.show(block=config['block'])
496+
497+
if config['returnfig']:
498+
return (fig, axlist)
488499

489500
# rcp = copy.deepcopy(plt.rcParams)
490501
# rcpdf = rcParams_to_df(rcp)
491502
# print('type(rcpdf)=',type(rcpdf))
492503
# print('rcpdfhead(3)=',rcpdf.head(3))
493504
# return # rcpdf
494-
495505

496506

497507
def _valid_addplot_kwargs():

0 commit comments

Comments
 (0)