Txt文件数据未显示在Matplotlib图形上
我将学习这个关于MPL中实时更新图的教程 当我运行程序时,网格显示出来,但没有从文本文件导入数据并生成任何类型的线图,并向我抛出一个“FileNotFoundError:[Errno 2]没有这样的文件或目录:'C:\Users\emira\Desktop\sample\u for_live\u graph.txt'”错误。有什么好处Txt文件数据未显示在Matplotlib图形上,matplotlib,graph,Matplotlib,Graph,我将学习这个关于MPL中实时更新图的教程 当我运行程序时,网格显示出来,但没有从文本文件导入数据并生成任何类型的线图,并向我抛出一个“FileNotFoundError:[Errno 2]没有这样的文件或目录:'C:\Users\emira\Desktop\sample\u for_live\u graph.txt'”错误。有什么好处 import matplotlib.animation as animation from matplotlib import style style.u
import matplotlib.animation as animation
from matplotlib import style
style.use("fivethirtyeight")
figure = plt.figure()
axis1 = figure.add_subplot(1,1,1)
def animate(interval):
graph_data = open(r"C:\Users\emira\Desktop\sample_for_live_graph.txt").read()
lines = graph_data.split("\n")
xs = []
ys = []
for line in lines:
if len(line)>1:
x, y = line.split(",")
xs.append(x)
ys.append(y)
axis1.clear()
axis1.plot(xs, ys)
ani = animation.FuncAnimation(figure, animate, interval = 1000)
plt.show()```