0
我們有來自Vicon Nexus運動捕捉軟件的代碼。使用Python,我們生成從EMG模擬源捕獲的圖形。 包含的振幅與頻率列是無關的。我們無法評論指出,在第二欄填寫的代碼段,但仍然留下第2欄。試圖擺脫matplotlib圖中的列
def plot(axrow, ax, ay, alim, bx, by, blim, emgLabel):
axrow[0].plot(ax, ay, color='blue', label=emgLabel)
axrow[0].set_xlim(alim)
axrow[0].set_xlabel('Time/s')
axrow[0].set_ylabel('Volt./V', fontsize=9)
axrow[0].legend()
axrow[0].locator_params(axis='y', nbins=3)
#axrow[1].plot(bx, by, color='red', label=emgLabel)
#axrow[1].set_xlim(blim)
#axrow[1].set_xlabel('Frequency/Hz')
#axrow[1].set_ylabel('Ampl./ a.u.', fontsize=9)
#axrow[1].legend()
#axrow[1].locator_params(axis='y', nbins=3)
空次要情節當我們改變參數從次要情節2比1,只有一列顯示,但情節是完全空
nrows = len(channelId)
fig, axes = plt.subplots(nrows, 1)
有8個通道annelIDs
任何幫助,將不勝感激。謝謝
編輯:對不起,延遲響應。我們終於能夠通過使用「squeeze = false」來找出解決方案。
這裏是FO爲清楚起見,該代碼的條款內容
from __future__ import division, print_function
import ViconNexus
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter
# define butterworth bandpass filter
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut/nyq
high = highcut/nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, data)
return y
#plot(row, timeLineCut, x, alim, freq, np.abs(y), blim, emgLabel)
def plot(axrow, ax, ay, alim, bx, by, blim, emgLabel):
axrow[0].plot(ax, ay, color='blue', label=emgLabel)
axrow[0].set_xlim(alim)
axrow[0].set_xlabel('Time/s')
axrow[0].set_ylabel('Volt./V', fontsize=9)
axrow[0].legend()
axrow[0].locator_params(axis='y', nbins=3)
#axrow[1].plot(bx, by, color='red', label=emgLabel)
#axrow[1].set_xlim(blim)
#axrow[1].set_xlabel('Frequency/Hz')
#axrow[1].set_ylabel('Ampl./ a.u.', fontsize=9)
#axrow[1].legend()
#axrow[1].locator_params(axis='y', nbins=3)
vicon = ViconNexus.ViconNexus()
# Extract information from active trial
subjectName = vicon.GetSubjectNames()[0]
sessionLoc = vicon.GetTrialName()[0]
trialName = vicon.GetTrialName()[1]
analogId = 3
emgOutId = 1
channelNames = vicon.GetDeviceOutputDetails(3, 1)[4]
channelId = vicon.GetDeviceOutputDetails(3, 1)[5]
nrows = 4
fig, axes = plt.subplots(nrows, 1, squeeze=False)
# over all analog channels
for ii, row in zip(range(nrows), axes):
emgId = channelId[ii]
emgData = vicon.GetDeviceChannel(analogId, emgOutId, emgId)[0]
emgDataRate = vicon.GetDeviceChannel(analogId, emgOutId, emgId)[2]
emgDataArray = np.asarray(emgData)
timeLine = np.arange(emgDataArray.size)
# write routine to select Left/right from trial_name
if channelNames[ii][-1] == 'R':
testEvent = vicon.GetEvents(subjectName, 'Right', 'Foot Strike')
testEventOff = vicon.GetEvents(subjectName, 'Right', 'Foot Off')
else:
testEvent = vicon.GetEvents(subjectName, 'Left', 'Foot Strike')
testEventOff = vicon.GetEvents(subjectName, 'Left', 'Foot Off')
trajDataRate = vicon.GetFrameRate()
if len(testEventOff[0]) == 1:
startFrameTraj = testEvent[0][0]
footOffFrame = testEventOff[0][0]
stopFrameTraj = testEvent[0][1]
else:
startFrameTraj = testEvent[0][0]
footOffFrame = testEventOff[0][1]
stopFrameTraj = testEvent[0][1]
startFrameAnal = int(startFrameTraj * (emgDataRate/trajDataRate))
footOffAnal = int(footOffFrame * (emgDataRate/trajDataRate))
stopFrameAnal = int(stopFrameTraj * (emgDataRate/trajDataRate))
emgDataCut = emgDataArray[startFrameAnal:stopFrameAnal]
T = 1.0/4000.0 # time per frame
tEnd = T * (emgDataCut.size - 1)
timeLineCut = np.linspace(0.0, tEnd, num=emgDataCut.size)
#timeLineCut = np.arange(emgDataCut.size)
# do some filtering
fs = emgDataRate # sample rate
lowCut = 40.0 # Hz
highCut = 800.0 # Hz
order = 6 # or 2, 4 ...?
x = butter_bandpass_filter(emgDataCut, lowCut, highCut, fs, order)
# another style for fft
Y = emgDataCut
y = np.fft.fft(Y)
freq = np.fft.fftfreq(len(Y), T)
alim = [0, tEnd+1]
blim = [0, 600]
emgLabel = channelNames[ii]
plot(row, timeLineCut, x, alim, freq, np.abs(y), blim, emgLabel)
fig.suptitle('EMG and spectrum - %s - %s' % (subjectName, trialName))
fig.set_size_inches(6, 10) # for landscape
fig.savefig('%s%s_%s_EMG.pdf' % (sessionLoc, subjectName, trialName))
請讀[mcve]。即我們需要一個完整的例子來看看這裏發生了什麼。 – ImportanceOfBeingErnest
我認爲axrow變量通過減少數字的數量而變得混亂,但沒有更多的代碼我只能猜測。附:你能修理縮進嗎? – Jurgy
@YerevanMotion這些評論意味着你可以相應地編輯你的問題。如果你忽視那些不會讓你更接近解決方案的東西。 – ImportanceOfBeingErnest