使用 Matplotlib 实时绘图。 X 轴被覆盖
Real time plotting using Matplotlib. X axis getting over-written
我正在使用重复打开的文件中的解析数据绘制实时数据。在 X 轴(时间)用完一个房间之前,绘图效果很好。我试图找出一种方法来前进到下一个元素并将时间值向左移动。此处包含代码和屏幕截图。
import matplotlib.pyplot as plt
import csv
import datetime
from matplotlib.animation import FuncAnimation
x = []
y = []
rssi_val = []
def animate(i):
with open('stats.txt', 'r') as searchfile:
# time = (searchfile.read(5))
time = (searchfile.read(8))
for line in searchfile:
if 'agrCtlRSSI:' in line:
rssi_val = line[16:20]
y.append(rssi_val)
x.append(time[-1])
plt.cla()
plt.plot(x,y)
next(x)
plt.xlabel('Time')
plt.ylabel('RSSI')
plt.title('Real time signal strength seen by client X')
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), animate, interval=5000)
plt.show()
你可以旋转标签,
for label in ax.get_xticklabels():
label.set_rotation(90)
或
ax.tick_params('x', labelrotation=90)
在 调用 plt.plot()
之前。
import matplotlib.pyplot as plt
import csv
import datetime
from matplotlib.animation import FuncAnimation
x = []
y = []
rssi_val = []
def animate(i):
with open('stats.txt', 'r') as searchfile:
# time = (searchfile.read(5))
time = (searchfile.read(8))
for line in searchfile:
if 'agrCtlRSSI:' in line:
rssi_val = line[16:20]
y.append(rssi_val)
x.append(time[-1])
plt.cla()
plt.plot(x,y)
next(x)
plt.xlabel('Time')
plt.ylabel('RSSI')
plt.title('Real time signal strength seen by client X')
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), animate, interval=5000)
plt.show()
你可以旋转标签,
for label in ax.get_xticklabels():
label.set_rotation(90)
或
ax.tick_params('x', labelrotation=90)
在 调用 plt.plot()
之前。