Matplotlib图形线不显示?

时间:2018-11-14 02:50:38

标签: python user-interface matplotlib

非常简单的程序。不确定为什么不显示图形线。其他一切正在更新/显示正常。

我只是想对我的CPU频率与时间进行建模。

任何人都知道为什么我的行不显示吗?我环顾四周,但似乎找不到类似的问题。

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()

0 个答案:

没有答案
相关问题