在过去的几天里,我一直在玩Numpy和matplotlib.我在尝试使matplotlib绘制函数而不阻塞执行时遇到问题.我知道在这里已经有很多线索提出了类似的问题,而且我已经搜索了很多但是没有设法让这项工作成功.
我曾经尝试过使用show(block = False),但我得到的只是一个冻结的窗口.如果我只是调用show(),则会正确绘制结果,但会阻止执行直到窗口关闭.从我读过的其他主题,我怀疑show(block = False)是否有效取决于后端.它是否正确?我的后端是Qt4Agg.你能看看我的代码并告诉我你是否看错了吗?这是我的代码.谢谢你的帮助.
from math import *
from matplotlib import pyplot as plt
print plt.get_backend()
def main():
x = range(-50, 51, 1)
for pow in range(1,5): # plot x^1, x^2, ..., x^4
y = [Xi**pow for Xi in x]
print y
plt.plot(x, y)
plt.draw()
#plt.show() #this plots correctly, but blocks execution.
plt.show(block=False) #this creates an empty frozen window.
_ = raw_input("Press [enter] to continue.")
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
PS.我忘了说我想在每次绘制内容时更新现有窗口,而不是创建一个新窗口.
import os
import numpy as np
from scipy.signal import *
import csv
import matplotlib.pyplot as plt
from scipy import signal
from brainflow.board_shim import BoardShim, BrainFlowInputParams, LogLevels, BoardIds
from brainflow.data_filter import DataFilter, FilterTypes, AggOperations, WindowFunctions, DetrendOperations
from sklearn.cluster import KMeans
#Options to read: 'EEG-IO', 'EEG-VV', 'EEG-VR', 'EEG-MB'
data_folder = 'EEG-IO'
# Parameters and bandpass filtering
fs = 250.0
# Reading data files
file_idx = 0
list_of_files = [f for f in os.listdir(data_folder) if os.path.isfile(os.path.join(data_folder, f)) and '_data' in f] #List of …Run Code Online (Sandbox Code Playgroud)