问题描述
我正在尝试重新创建视觉刺激实验。首先,根据我想要的刺激次数,我创建了随机坐标点。当我向某人显示图像后,如果图片上出现蓝色圆圈,则他们必须按'p',否则请按'a'。该代码有效,但是第一个键盘输入未更新图像,第二个输入后该图像得到更新,但是由于第二个输入使第二个图像显示,因此它已经是前面的一个输入。我为第二张图像输入的内容已经为第三张记录了,依此类推。重要的部分是在创建分数数组之后。有人可以说明我的错误以及如何解决吗?
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import keyboard
import time
def random_coordinates(n): #Function to create random coordinates for the signal or nosignal
randcoord = []
x = np.random.randint(0,101,2*n) #create random coordinates (X,Y) for each signal or distractor
randcoord.append(x)
return randcoord
def graphs_presentabsent(randcoord,y,n): #Graphs depending on if there is a signal present or not for 4
if y == 1 and n==4: #If signal is present uses this to create 4 markers with random coordinates
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],randcoord[0][1],'bo',randcoord[0][2],randcoord[0][3],'ro',randcoord[0][4],randcoord[0][5],\
'ro',randcoord[0][6],randcoord[0][7],ms = 22,fillstyle = 'none')
plt.title("Press 'p' if stimulus present or 'a' if absent",fontsize = 20)
plt.show()
elif y == 0 and n==4: #If no signal is present uses this to create 4 markers with random coordinates
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],fontsize = 20)
plt.show()
elif y == 1 and n==8 : #If signal is present uses this to create 8 markers with random coordinates
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],randcoord[0][8],randcoord[0][9],randcoord[0][10],\
randcoord[0][11],randcoord[0][12],randcoord[0][13],randcoord[0][14],randcoord[0][15],\
ms = 22,fillstyle = 'none')
plt.title("Press 'p' if stimulus present or 'a' if absent",fontsize = 20)
elif y == 0 and n==8: #If no signal is present uses this to create 8 markers with random coordinates
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],fillstyle = 'none')
plt.title("Press 'p' if stimulus present or 'a' if absent",fontsize = 20)
elif y == 1 and n==12:
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],\
randcoord[0][16],randcoord[0][17],randcoord[0][18],randcoord[0][19],randcoord[0][20],\
randcoord[0][21],randcoord[0][22],randcoord[0][23],fillstyle = 'none')
plt.title("Press 'p' if stimulus present or 'a' if absent",fontsize = 20)
elif y == 0 and n==12:
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],fontsize = 20)
elif y == 1 and n==16:
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],randcoord[0][24],randcoord[0][25],\
randcoord[0][26],randcoord[0][27],randcoord[0][28],randcoord[0][29],randcoord[0][30],\
randcoord[0][31],fillstyle = 'none')
plt.title("Press 'p' if stimulus present or 'a' if absent",fontsize = 20)
elif y == 0 and n==16:
figManager = plt.get_current_fig_manager() #Full Screen Window
figManager.window.showMaximized()
plt.plot(randcoord[0][0],fontsize = 20)
sets = [4,8,12,16] #set values for the number of stimuli displayed
scores = [] # vector to keep all scores
for ix in sets:
for iy in range(3):
fig = plt.figure(1,clear = True)
y = np.random.randint(0,2) #generates randomly 1 or 0,if it is 1 the image will have signal
stimuluscoords = random_coordinates(ix)
graphs_presentabsent(stimuluscoords,ix)
#When the item appears on the screen
startTime = time.time()
plt.waitforbuttonpress()
#When the user presses p or a
endTime = time.time()
reactionTime = endTime - startTime
if keyboard.is_pressed('p'):
letter = 'p'
if keyboard.is_pressed('a'):
letter = 'a'
if (letter == 'a' and y == 0) or (letter == 'p' and y == 1):
temp = [reactionTime,ix]
scores.append(temp)
else:
reactionTime = 0
fig.canvas.draw()
fig.canvas.flush_events()
plt.close()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)