0

I'd like to display my spectrogram data accompanied with a line graph depicting some relevant data. Spectrogram was made with scipy and data is in a Pandas dataframe.

I tried referencing a matplotlib example but it just sticks a blank line graph in the second plot.

https://matplotlib.org/gallery/lines_bars_and_markers/csd_demo.html#sphx-glr-gallery-lines-bars-and-markers-csd-demo-py

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()

I was hoping I would get a nice line plot on the top and the spectrogram below but no dice! Instead I got the expected line plot up top and a blank line plot below.

BikeControl
  • 179
  • 2
  • 9

0 Answers0