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