2017-10-11 3 views
0

Vicon Nexusのモーションキャプチャソフトウェアに付属しているこのコードがあります。 Pythonを使用して、EMGアナログソースから取得したグラフを生成します。 Amplitude vs Frequency列は含まれていません。私たちは、2番目の列に埋めコードのセクションをコメントアウトすることができますが、私たちはからサブプロットの引数を変更すると、それはまだ列2matplotlibグラフの列を取り除こうとしています

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) 

Second Column Empty

で空のサブプロットを残し2 1に、1つの列のみが表示されますが、プロットは、8 chがあります

nrows = len(channelId) 
fig, axes = plt.subplots(nrows, 1) 

One Column, No Graphs

完全に空になっていますannelIDs

助けていただければ幸いです。ありがとうございます

編集:遅れています。 「squeeze = false」を使用して、最終的に解決策を見つけ出すことができました。ここで

は明快

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)) 
+0

にcolmunsの数を切り替えてください[mcve]を読んでください。私。ここで何が起こっているかを見るためには完全な例が必要です。 – ImportanceOfBeingErnest

+0

私は、axrow変数が数字の数を減らすことによってぶち壊されると思うが、私は推測することができるコードはこれ以上ない。 P.S.あなたはインデントを修正できますか? – Jurgy

+0

@ YerevanMotionこれらのコメントは、それに応じてあなたの質問を編集するためのものです。あなたがそれらを無視すれば、それはあなたを解決に近づかせません。 – ImportanceOfBeingErnest

答えて

0

のコードソリューションFO entirityがあなたにしているサブプロット引数に「偽スクイズを=」を使用し、1

fig, axes = plt.subplots(nrows, 1, squeeze=False) 
関連する問題