Adam Gabryś - 7 months ago 30
Python Question

# Visualization of wavelets coefficients for different deconstruction levels

I am doing some visualizations for a wavelet presentation. I need to prepare a plot similar to this one on right side:

I have been trying to reach this goal with spectogram, and I am trying for more than hour to find at least name of such plot.

This plot represents coefficients of details of a wavelet transformation at different levels (1, 2, 3, and 4). On the left side, you see a function with a threshold. The coefficients value is represented by color (black close to 0, brownie higher value).

With every level of wavelet decomposition the number of coefficients is reduced by half. So one level small ranges of samples, four levels four times larger samples.

How can I do that?

Well, your question assumes quite some other questions but I think you might be looking for pcolormesh. For instance used this way (I'll put it in a grid just like your example picture, the data is randomly generated):

``````import matplotlib.pyplot as plt
import numpy as np

ax1 = plt.subplot2grid((4,4),(0, 0),rowspan=1,colspan=1)
ax2 = plt.subplot2grid((4,4),(1, 0),rowspan=1,colspan=1)
ax3 = plt.subplot2grid((4,4),(2, 0),rowspan=1,colspan=1)
ax4 = plt.subplot2grid((4,4),(3, 0),rowspan=1,colspan=1)

ax5 = plt.subplot2grid((4,4),(0, 1),rowspan=2,colspan=3)
ax6 = plt.subplot2grid((4,4),(2, 1),rowspan=2,colspan=3)

ax1.plot(range(100),np.random.randint(-100,100,100)/np.arange(1,101,1)**1,color='green')
ax1.axhline(10,color='orange',linestyle='--')
ax1.axhline(-10,color='orange',linestyle='--')
ax1.set_ylim(-20,20)
ax1.set_xticks([])
ax1.set_ylabel('D4',rotation=0)

ax2.plot(range(100),np.random.randint(-100,100,100)/np.arange(1,101,1)**1,color='green')
ax2.axhline(10,color='orange',linestyle='--')
ax2.axhline(-10,color='orange',linestyle='--')
ax2.set_ylim(-20,20)
ax2.set_xticks([])
ax2.set_ylabel('D3',rotation=0)

ax3.plot(range(100),np.random.randint(-100,100,100)/np.arange(1,101,1)**1,color='green')
ax3.axhline(10,color='orange',linestyle='--')
ax3.axhline(-10,color='orange',linestyle='--')
ax3.set_ylim(-20,20)
ax3.set_xticks([])
ax3.set_ylabel('D2',rotation=0)

ax4.plot(range(100),np.random.randint(-100,100,100)/np.arange(1,101,1)**1,color='green')
ax4.axhline(10,color='orange',linestyle='--')
ax4.axhline(-10,color='orange',linestyle='--')
ax4.set_ylim(-20,20)
#ax4.set_xticks([])
ax4.set_ylabel('D1',rotation=0)

X,Y = np.meshgrid(range(1000),range(4))
Z = np.random.randint(0,100,(4,1000))

ax5.pcolormesh(X,Y,Z,cmap = 'copper')
ax5.set_yticks([i for i in range(4)])