我正在研究一种可视化几年内急剧变化的数据的方法,并且正在使用下面的代码来实现:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
import pandas as pd
data = pd.read_pickle('/path/to/pickle file')
y = data['Total'].values
x = list(range(len(y)))
fig = plt.figure()
ax = fig.add_subplot(111)
line, = ax.plot([],[], '-')
#ax.set_xlim(np.min(x), np.max(x))
#ax.set_ylim(np.min(y), np.max(y))
def animate(i):
ax.relim()
ax.autoscale_view()
line.set_xdata(x[:i])
line.set_ydata(y[:i])
return line,
ani = animation.FuncAnimation(fig, animate, interval=10, blit=True)
plt.show()
上面的所有内容基本上都能按预期工作,但是当实际绘制数据图形时,随着时间的推移,我得到了x和y轴的正确自动缩放,但是在下图的最终图片中看不到任何线:
但是,放大(即使稍微放大)也可以显示线条(如下):
这不是线宽的问题,因为即使将其设置为一个非常大的数字,在放大之前也不会显示该图,因此我不完全确定发生了什么/如何解决此问题。
我希望能够在动画过程中看到一条“看似”固定宽度的线,就像上面放大的图片一样。