里面是一些链接好的文章
- Python–matplotlib绘图可视化知识点整理
- matplotlib事件处理基础(事件绑定、事件属性
- Python借助keyboard监听键盘事件
import random
import keyboard
from matplotlib import pyplot as plt
class rand():
def __init__(self,num):
self.index = 1
self.num =num
self.x =[]
self.list_y =[]
[self.list_y.append([]) for i in range(self.num)]
def flag(self,event):
a = keyboard.KeyboardEvent('down', 28, 'A')
if event.event_type == 'down' and event.name == a.name:
self.index = -self.index
print(self.index)
def rand_num(self):
[self.list_y[i].append(random.randrange(0,10)) for i in range(self.num)]
self.x.append(len(self.list_y[0]))
def show_plt(self):
color = ['green','red','blue','skyblue']
keyboard.hook(self.flag)
while True:
if self.index == 1:
self.rand_num()
[plt.plot(self.x,self.list_y[i], color=color[i%4]) for i in range(self.num)]
plt.xlabel('site')
plt.ylabel('length')
plt.pause(1.5)
if __name__ == '__main__':
plt_show = rand(5)
plt_show.show_plt()