Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature Request: support animation/live updating of OHLCV data plots. #25

Description

@andresberejnoi

Is your feature request related to a problem? Please describe.
I am trying to rewrite a live chart plotting function I had with the previous mpl-finance module by using matplotlib animation.FuncAnimation method (documentation here).

The function expects to be passed a figure where to draw. For the func argument, I am passing a simple function animate_plot:

class Plotter(object):
...
    def plot_live_chart(self,ohlc_data):
        def animate_plot(df_generator, *fargs):
            _type = fargs[0]
            mplfinance.plot(df_generator,type=_type)
     
        fig = plt.figure()
        ax1 = fig.add_subplot(1,1,1)
        #ani = animation.FuncAnimation(fig,animate_plot,interval=self.plot_refresh_rate,blit=True) #blit=True means to only re-draw parts that have changed
        ani = animation.FuncAnimation(fig,animate_plot,frames=ohlc_data.iterrows(),fargs=(self.type,),interval=self.plot_refresh_rate)

When I run my code, I only get a blank canvas at the end. I am thinking that it could be because on each call to mplfinance.plot a new figure is created but I am not really sure.
Describe the solution you'd like
I would like to have another parameter option for mplfinance.plot to provide a previously created figure. Then it could be checked internally to see if the parameter was provided then that figure is used. If not, then the normal code creates one.

I think it could also be useful to have the function return the figure so it can still be used later. If these are things that are already possible then could you point me in the right direction where to find it?

Describe alternatives you've considered
I think it would be great if a live plotter method were implemented with mplfinance so there is no need to build around it.
It could be a method that uses the already existing .plot() similar to what I am doing above but better. This method could either animate a full dataframe like historical data and it could also animate continuously updating data.

I think this fits better for another feature request. I may open one soon once I have more time to think of how it could be implemented.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions