Построение PolyCollection 3d с данными спектрограммы в matplotlib - PullRequest
0 голосов
/ 20 февраля 2019

Я пытаюсь построить поликоллекцию из выходных данных функции спектрограммы.

# TestData
test=np.random.rand(1000000)*100    
# Calc spectrogram
fa = 2e6  # Sampling Rate
fAx_signal, tAx_signal, STFTspec_signal = spsi.spectrogram(test, fa, 
nperseg=1024)
# get power for Frequency Bins (so i have the Frequency/Power for every Timestep)
freq_power_dict = {}
for k in range(0, len(tAx_signal)):
    power_list_t = []
    for i in range(0, len(fAx_signal)):
        power_list_t.append(STFTspec_signal[i][k])
    power_list_t_log = 20 * np.log10(power_list_t)
        freq_power_dict[k] = power_list_t_log

    # Polyplot from Matplotlib Docs for the "raw Data of the spectrogram function
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
from mpl_toolkits.mplot3d import axes3d
import numpy as np

# I think here is something wrong in my Code

freq_data = fAx_signal
amp_data = STFTspec_signal
time_data = tAx_signal

# this is from a user here at sof

verts = []
for itime in range(len(time_data)):
    # I'm adding a zero amplitude at the beginning and the end to get a nice
    # flat bottom on the polygons
    xs = np.concatenate([[freq_data[0, itime]], freq_data[:, itime], [freq_data[-1, itime]]])
    ys = np.concatenate([[0], amp_data[:, itime], [0]])
    verts.append(list(zip(xs, ys)))

poly = PolyCollection(verts)
poly.set_alpha(0.7)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.add_collection3d(poly, zs=time_data, zdir='y')
ax.set_xlim3d(freq_data.min(), freq_data.max())
ax.set_xlabel('Frequency')
ax.set_ylim3d(time_data.min(), time_data.max())
ax.set_ylabel('Time')
ax.set_zlim3d(amp_data.min(), amp_data.max())
ax.set_zlabel('Amplitude')

plt.show()

Я хочу видеть мощность частоты для каждого временного шага в трехмерном полиплоте.Это всего лишь пример того, что я хотел, я использую некоторые аналогичные данные для своей работы.

Жду ваших ответов и заранее благодарю.

С наилучшими пожеланиями Бастиан

...