我想显示我的频谱图数据,并附上描述某些相关数据的折线图。频谱图是用scipy制作的,数据在Pandas数据框中。
我尝试引用matplotlib示例,但它只是在第二个图中粘贴了空白线图。
import pandas as pd
from scipy import signal
import matplotlib.pyplot as plt
#Import data file
df = pd.read_csv("C:\Phoenix Test Logs\TorqueTest\Hartford Testing\HartfordTest_2019-01-31_12,15,37.csv")
st = 0.3 #Set start time of spectrum analysis
dur = 10.1 #Set duration of spectrum analysis
si = df[df['Time [s]']>=st].index.values.astype(int)[0]
ei = df[df['Time [s]']>=st+dur].index.values.astype(int)[0]
df = df[si:ei] #Isolate the desired section of interest
fs = 1/(df['Time [s]'][si+1]-df['Time [s]'][si])#Find the frequency
data = df['Torque [lb-in]'].values #Get torque values as a numpy array
f, t, Sxx = signal.spectrogram(data, fs) #Run spectrogram analysis
fig, (ax1, ax2) = plt.subplots(2,1)
fig.subplots_adjust(hspace=0.5)
ax1.plot(df['Time [s]'],df['ESC_RPM_1 [RPM]'],df['Time [s]'],df['ESC_Command_1 [usec]'])
ax1.xlabel('Time [s]')
ax1.ylabel('RPM & Cmd')
ax2.pcolormesh(t, f, Sxx)
ax2.ylabel('Frequency [Hz]')
ax2.ylim(0,200)
ax2.xlabel('Time [sec]')
plt.show()
我希望上面能得到不错的线条图,而下面的能谱图却没有骰子!取而代之的是,我在上面得到了预期的线图,而在下面得到了一个空白线图。