# Plotting Hilbert and Marginal Spectra in Python

I am using the PyEMD package for python 3.6. I want to create a 2d plot of hilbert spectrum (x: Time, y: Frequency, Colorbar: Amplitude) and the Marginal Spectrum (x: Frequency, y: Amplitude)

I can compute the instantaneous phase, frequency and amplitude of every IMFs:

import numpy as np
import pylab as plt
from scipy.signal import hilbert

from PyEMD import EMD

def instant_phase(imfs):
"""Extract analytical signal through Hilbert Transform."""
analytic_signal = hilbert(imfs)  # Apply Hilbert transform to each row
phase = np.unwrap(np.angle(analytic_signal))  # Compute angle between img and real
return phase

def instant_amplitude(imfs):
"""Extract analytical signal through Hilbert Transform."""
analytic_signal = hilbert(imfs)  # Apply Hilbert transform to each row
analytic_amplitude = np.abs(analytic_signal) ## Compute amplitude
return analytic_amplitude

# Define signal
t = np.linspace(0, 1, 200)
dt = t[1]-t[0]

sin = lambda x, p: np.sin(2*np.pi*x*t+p)
S = 3*sin(18, 0.2)*(t-0.2)**2
S += 5*sin(11, 2.7)
S += 3*sin(14, 1.6)
S += 1*np.sin(4*2*np.pi*(t-0.8)**2)
S += t**2.1 -t

# Compute IMFs with EMD
emd = EMD()
imfs = emd(S, t)

# Extract instantaneous phases, frequencies and amplitude using Hilbert transform
instant_phases = instant_phase(imfs)
instant_freqs = np.diff(instant_phases)/(2*np.pi*dt)
instant_amplitude = instant_amplitude(imfs)


Now I am stuck and don't know how to compute and plot these formulas:

Wikipedia: Hilbert Spectrum

Can someone help me out?