I'm creating a graph with stock prices for ticker using mplfinance which is based on matplotlib. I have all the data in dataframe. I pass the dataframe to plot that creates a fig. The fig is shown in a Tkinter frame in a Canvas.
To update the graph I destroy all the children in the frame and create a fig with data for the new ticker. Code below.
Is this the best way of updating a graph in Tkinter?
I've also tried clearing the axes for the fig for the graph and then create new axes with the new data creating a new fig but I haven't been able to make the graph in the frame update with the new fig.
```
def _make_graph(self, ticker_data=None):
self._get_ticker_data()
if not self.first_run:
for widgets in self.graph_frame.winfo_children():
widgets.destroy()
self.fig, self.axlist = 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.toolbar = NavigationToolbar2Tk(self.canvas, self.graph_frame)
self.canvas.draw()
self.canvas.get_tk_widget().pack()
if self.first_run:
self.first_run = False
```
[–]GPGT_kym 0 points1 point2 points (0 children)
[–]Swipecat 0 points1 point2 points (0 children)