matplotlib / mplfinance

Financial Markets Data Visualization using Matplotlib
https://pypi.org/project/mplfinance/
Other
3.48k stars 613 forks source link

Feature Request: Add SubFigures to Mpf_Figure #664

Open traderjoe1968 opened 3 months ago

traderjoe1968 commented 3 months ago

Presently the Mpf_Figure class does not support mpl subfigure plots. Subfigures allow encapsulation of a group of subcharts into one figure that can then be embedded easily in the overall figure

Adding the following function to Mpf_Figure class will add in subfigures

    def add_subfigure(self,*args,**kwargs):

        if 'style' in kwargs or not hasattr(self,'mpfstyle'):
            style = _check_for_and_apply_style(kwargs)
        else:
            style = _check_for_and_apply_style(dict(style=self.mpfstyle))

        sf = mplfigure.Figure.add_subfigure(self, *args, **kwargs)
        sf.mpfstyle = style
        self.subfigs += [sf]
        return sf

Current Alternative solution / workaround is to sub-class Mpf_Figure and add this in. It would be preferable not to have to do this as SubFigure are part of the mpl and should be supported in mpf

DanielGoldfarb commented 3 months ago

Yes, I've been thinking about this for a while. Thanks for the input and code. Definitely want to do this.

traderjoe1968 commented 3 months ago

It's a little more complicated to get this to work correctly. I have the basic stuff working, however I had to use external axes to pass in subfigure. It would be better for mpf plotting routine to take in a Fig/SubFigure param to use as the canvas.

This is very worthwhile as then the overall chart can be composed of multiple SubFigures. eg (Note: not currently working as I want)

Figure_1

mplot copy.py.txt