【发布时间】:2018-05-28 00:34:34
【问题描述】:
我是 matplotlib 的新手,我正在使用这个库来绘制 csv 文件中的数据。不使用动画功能,图表看起来是正确的,但是当我尝试使用动画时,图表连接了第一个点和最后一个点。我查了一些东西,但我不知道如何解决这个问题。有谁知道如何解决这个问题?下面是我的代码。提前致谢!
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import csv
x = []
y = []
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
with open("example.txt", "r") as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
x.append(int(row[0]))
y.append(int(row[1]))
ax1.clear()
ax1.plot(x,y)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
【问题讨论】:
标签: python-2.7 animation matplotlib