Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Ability to overlay a candle chart over another (share axes) #78

Open
GAEfan opened this issue Apr 3, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@GAEfan
Copy link

GAEfan commented Apr 3, 2020

Thank you for your work on updating mplfinance!

Using the deprecated mpl-finance, I was able to put 2 candlestick_ohlc() charts on top of each other (overlaid, sharing the same axes), and a table below the chart, all within a single figure that could be saved.

Now, I can use returnfig=True to export the figure and axes, but not sure how to actually use those later. ax is not a valid kwarg in plot(), as it was in candlestick_ohlc(). And not sure how to draw the chart inside a parent figure. Should fig be a kwarg for plot()?

Thank you.

@GAEfan GAEfan added the enhancement New feature or request label Apr 3, 2020
@GAEfan GAEfan changed the title Feature Request: Ability to overlay a candle chart over another Feature Request: Ability to overlay a candle chart over another (share axes) Apr 3, 2020
@DanielGoldfarb
Copy link
Collaborator

Ability to create and pass in your own Figure and Axes is coming. Maybe another 4 to 6 weeks. In the meantime, you may be able to use the Figure and Axes that are returned from returnfig=True kwarg.

I'd like to see an example of an two overlayed candle charts, if you could point me to an example that would be great. Thanks.

@GAEfan
Copy link
Author

GAEfan commented Apr 3, 2020

Hi Daniel,

Thank you for the prompt response. Yes, I can gather Figure and Axes from returnfig=True. However, how do I tell the second mfp.plot() to use the same axes? ax= is not yet part of the kwargs.

Here is an example of candles sharing the same axes via overlay. It is from a machine learning prediction machine: image

@GAEfan
Copy link
Author

GAEfan commented Apr 14, 2020

This can be handled with a couple of lines of code:

In _valid_plot_kwargs():

'fig'         : { 'Default'     : None,
                  'Validator'   : lambda value: isinstance(value,object) },

In plot():

fig = config['fig'] or plt.figure()

@DanielGoldfarb
Copy link
Collaborator

@GAEfan --

Do you have a working version of the code, with this change, that does the overlay that you want with mplfinance? I would like to look at it.

@DanielGoldfarb
Copy link
Collaborator

@GAEfan

Thank you for the prompt response. Yes, I can gather Figure and Axes from returnfig=True. However, how do I tell the second mfp.plot() to use the same axes? ax= is not yet part of the kwargs.

There have been a number of enhancements since this issue was first posted.

There now is kwarg ax= which you can use. So you can do:

fig, axlist = mpf.plot(df1,...,returnfig=True)

mpf.plot(df2,ax=axlist[0])

Please let me know if this is an adequate solution for your issue, or if we can do something else for you.
For more information see https://github.com/matplotlib/mplfinance/wiki/Acessing-mplfinance-Figure-and-Axes-objects

Thank you. All the best. --Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants