matplotlib / matplotlib/mplfinance

Update plot, remove old data show new data

Open
#542 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
4.4k
Forks
678
PR merge metrics
No merged PRs in 30d

Description

Thanks for an amazing library!

I'm trying to create an application where the user can select a ticker and then click a button that prints candlesticks for the ticker. I'm plotting the graph inside a frame in Tkinter.

image

The user can select a ticker in the drop down and Graph the data for the ticker.

image

I first create the empty graph

def _make_empty_graph(self):

    self.fig = mpf.figure()     
    self.canvas = FigureCanvasTkAgg(self.fig, self.graph_frame)
    self.canvas.get_tk_widget().pack()

I then create the graph with data from a dataframe, after the user has selected a ticker and clicked "Graph". I destroy the children in the frame to not add another graph under the previous graph. The user can then select yet another ticker and graph it.

def _make_graph(self, ticker_data=None):

    self._get_ticker_data()

    for widgets in self.graph_frame.winfo_children():
        widgets.destroy()

    self.fig, _ = mpf.plot(self.ticker_df, type='candle', 
        title = f'{self.ticker_var.get()}',
        volume=True, style='binance', returnfig=True)


    self.canvas = FigureCanvasTkAgg(self.fig, self.graph_frame)
    self.canvas.get_tk_widget().pack()

Can I solve this a bit more elegant by using subplots or similar and then just clear the graph before I create the new graph? I still want to show an empty graph in the beginning. Do I need to create the empty graph in some other way to be able to update it later? Later on I like to add buttons to be able to RSI, Bollinger bands etc. on top the candlesticks.

Suggestions are greatly appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the _make_empty_graph and _make_graph entry points shown in the issue, including the FigureCanvasTkAgg setup and graph_frame cleanup. Check how the plotting API handles replacing an existing figure and whether the requested empty initial graph and later indicators are supported. Done would require a documented, agreed approach, but no specific repository file or test is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, desktop
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.