Reputation: 31
I want to plot data, and then data with noise subtracted out of it on the same scale so I can accurately compare the two. What's the best way to do this? Right now I'm just doing:
f, t, Sxx = spectrogram(np.diff(rawdata), F_S)
plt.subplot(211)
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.colorbar()
f, t, Sxx = spectrogram(np.diff(rawdata - noise), F_S)
plt.subplot(212)
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.colorbar()
Where the diff is just for aesthetic reasons
Upvotes: 2
Views: 1511
Reputation: 1699
You can add vmin and vmax arguments to your call to pcolormesh. Set them to the max and min value of both your datasets. See https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.pcolormesh.html
f1, t1, Sxx1 = spectrogram(np.diff(rawdata), F_S)
f2, t2, Sxx2 = spectrogram(np.diff(rawdata - noise), F_S)
Sxx_min = np.amin(np.minimum(Sxx1, Sxx2))
Sxx_max = np.amax(np.maximum(Sxx1, Sxx2))
plt.subplot(211)
plt.pcolormesh(t1, f1, Sxx1, vmin=Sxx_min, vmax=Sxx_max)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.colorbar()
plt.subplot(212)
plt.pcolormesh(t2, f2, Sxx2, vmin=Sxx_min, vmax=Sxx_max)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.colorbar()
Upvotes: 1