【发布时间】:2021-07-09 20:41:37
【问题描述】:
我目前每 2 秒从 CSV 文件中读取数据点,并使用 matplotlib Funcanimation 绘制它。但是,x 轴上的日期刻度相互堆叠,因此不可读。我正在寻找一种有效的方法来排列 x-ticks,这样它们就不会堆叠在一起。
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import pandas as pd
def animate(i):
data = pd.read_csv('data.csv')
x = data.iloc[:,0]
y4 = data.iloc[:,4]
plt.cla()
plt.plot(x, y4, label = "value")
plt.legend(loc= 'upper left')
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), animate, interval = 2000)
plt.show()
【问题讨论】:
标签: python matplotlib matplotlib-animation