Очень простая программа.Не уверен, почему линия графика не отображается.Все остальное обновляется / отображается нормально.
Я просто пытаюсь смоделировать частоту моего процессора в зависимости от времени.
Кто-нибудь знает, почему моя строка не отображается?Я посмотрел вокруг, но не могу найти похожую проблему.
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
# Function to obtain CPU frequency from file 'cpuinfo'
def getfreq():
with open('/proc/cpuinfo', 'r') as f:
for line in f.readlines():
lineSplit = line.split(':')
if len(lineSplit) == 2:
lineSplit[0] = lineSplit[0].strip()
lineSplit[1] = lineSplit[1].strip()
if lineSplit[0] == "cpu MHz":
frequency = float(lineSplit[1])
return frequency
style.use('fivethirtyeight')
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
time = 0
def animate(i):
global time
frequency = getfreq()
xs = []
ys = []
xs.append(float(time))
time = time + 1
ys.append(frequency)
ax1.clear()
ax1.plot(xs, ys)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()