【发布时间】:2019-08-30 03:52:33
【问题描述】:
我正在尝试使用 w、a、s 和 d 键在 matplotlib 图周围移动一个点,而无需在每次键入字母后按 Enter。这使用 readchar.readchar() 有效,但随后情节不显示。我做错了什么?
""" Moving dot """
import matplotlib.pyplot as plt
import time
import readchar
x = 0
y = 0
q = 0
e = 0
counter = 0
while 1 :
#arrow_key = input()
arrow_key = readchar.readchar()
print(x,y)
if arrow_key == "d" :
q = x + 1
elif arrow_key == "a" :
q = x - 1
elif arrow_key == "w" :
e = y + 1
elif arrow_key == "s" :
e = y - 1
plt.ion()
plt.plot(x,y, "wo", markersize = 10)
plt.plot(q,e, "bo")
plt.xlim(-10,10)
plt.ylim(-10,10)
x = q
y = e
【问题讨论】:
标签: python matplotlib