I'm using the code below to get Frequency, Time and Power parameters resulting from STFT.
f,t,Z = signal.stft(x, fr, nperseg=40)
and getting the mesh plot by:
plt.pcolormesh(t, f, np.abs(Z), shading='gouraud')
plt.title('STFT Magnitude')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()
I'm looking for a way to derive that image as a grayscaled 2D NumPy matrix without actually plotting it. Another way would be saving the plot and loading it as a NumPy array and then converting it to a grayscale image, but it would cost a lot of computation time. I'm looking for a neat and effective way of deriving that 2D matrix.

