How to add a legend to the plots? For example, if using several moving averages it will be useful to show a legend to map moving averages to line plots.
Is clear how this is done using matplotlib but I did not see an example of how to do so using the mplfinance package.
TIA,
Rajeev,
Legends are not yet available in mplfinance. Hopefully soon (maybe a couple months or so).
In the meantime, if you want to play with matplotlib, you can try using the returnfig=True kwarg in mplfinance and attempt to display legends by having access to the Figure and Axes that mplfinance creates.
Alternatively if you would like to contribute code to mplfinance to make it easy for users to include legends, I would be happy to work together with you on getting that code correctly merged into mplfinance.
All the best. Thanks for you interest in mplfinance. --Daniel
Hi Daniel,
I appreciate your comments. I'll give it a try. This package seems to be going in a good direction. Can we have a side bar on how I can contribute code to the package? You can email me directly at [email protected].
All the best
--Rajeev
fig, axes = mpf.plot(df, type='candle', mav=mav_tuple, returnfig=True)
# Configure chart legend and title
axes[0].legend(mav_titles)
axes[0].set_title(ticker)
# Save figure to file
fig.savefig(path_to_figure)
This does the trick thanks to the help of mr. Daniel Goldfarb.
@arthurpdesimone
Thank you for posting a specific example to help others. Much appreciated. All the best. --Daniel
Most helpful comment
Plot chart to figure and axis object
This does the trick thanks to the help of mr. Daniel Goldfarb.