Discussion:
[Matplotlib-users] How to convert time to angle in matplotlib's spectrogram?
nxkryptor nxkr
2015-05-13 08:38:49 UTC
Permalink
I have a pressure transducer signal along with the crank angle from an
internal combustion engine. A sample data is available here
<https://drive.google.com/file/d/0BwwhEMUIYGyTdmtlT3lwMHFmVzQ/view?usp=sharing>
.

Now, I am trying to plot the spectrogram of this pressure signal using the
code below:

import matplotlib.pyplot as pltimport numpy as np


data = np.genfromtxt('data.dat', skiprows = 1, delimiter='\t')
angle = data[:, 0]
pressure = data[:, 1]


fig = plt.figure(figsize=(5.15, 5.15))
fig.clf()
plot = plt.subplot(111)
cax = plt.specgram(pressure * 100000, NFFT = 512, Fs = 10000)
plot.grid(False, which="major")
plot.set_xlim(right = max(cax[2]))
plot.set_xlabel('Time (s)', labelpad=6)
plot.set_ylabel('Frequency (Hz)', labelpad=6)
y_min, y_max = plot.get_ylim()
plt.gca
cbar = plt.colorbar(orientation='vertical', ax = plot, fraction =
0.046, pad = 0.04) #fraction=0.0458, pad=0.04)
cbar.set_label('Power spectral density (dB)', rotation=-90)
plt.show()


Now *I want the spectrogram to be plotted with angle on the x-axis*. How
can I convert the x-axis to angles as available in the data file?

Regards,
nxkr

Loading...