0

I am trying to animate stock prices from a csv file on a matplotlib graph and embed this onto tkinter. The issue is that I can't seem to get it to work with tkinter.

The issue I am having is that it only shows a matplotlib graph on the tkinter window without anything on it as shown on the image.

Output:

Output

When I run a split terminal and run my other script to generate the prices and another script to animate this using just matplotlib and no tkinter it works, but whenever I try to add it to a tkinter window it doesn't.

Here is my code:

import tkinter
from matplotlib.backends.backend_tkagg import (
    FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib import pyplot as plt, animation
import pandas as pd

root = tkinter.Tk()
root.title("Embed Animation to Tkinter frame")

fig = plt.Figure(dpi=100)
ax = fig.add_subplot(111)
line, = ax.plot([], [])

canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()

canvas.get_tk_widget().pack()

def animate(i):
    data = pd.read_csv('data.csv')
    x = data['x_value']
    price = data['stock_price']
    line.set_data(x, price)
    return line,

anim = animation.FuncAnimation(fig, animate, interval=1000)
tkinter.mainloop()

I have watched countless videos on matplotlib animations on tkinter, and I cannot seem to figure out why it isn't working.

Contents of the csv file:

contents of the csv file

1 Answer 1

0

There might be not coded with plot options. Try with adding the below code:

line=plt.plot(variable, variable, color='skyblue', marker='o', markerfacecolor='blue', markersize=6)[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.