I would like to plot four curves, to the left two temporal curves and to the rigth two FFTs based on the temporal curves. So for instance:
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
Fs=1024
t=np.arange(0,10,1/Fs)
F=np.arange(0,10,1/Fs)
x = np.sin(2 * 3.1416 * F *t )
plt.figure()
ax1 = plt.subplot(221)
plt.plot(t,x)
ax2 = plt.subplot(222)
f, Pxx_den = signal.periodogram(x, Fs)
line1, = plt.plot(f[:np.where(f>50)[0][0]],Pxx_den[:np.where(f>50)[0][0]] )
ax3 = plt.subplot(223, sharex=ax1)
plt.plot(t,x)
ax4 = plt.subplot(224)
f, Pxx_den = signal.periodogram(x, Fs)
line1, = plt.plot(f[:np.where(f>50)[0][0]],Pxx_den[:np.where(f>50)[0][0]] )
def on_xlims_change1(axes):
lim = axes.get_xlim()
f, Pxx_den = signal.periodogram(x[np.bitwise_and(t >lim[0] , t <lim[1])], Fs)
ax2.clear()
ax2.plot(f[:np.where(f>50)[0][0]],Pxx_den[:np.where(f>50)[0][0]] )
def on_xlims_change2(axes):
lim = axes.get_xlim()
f, Pxx_den = signal.periodogram(x[np.bitwise_and(t >lim[0] , t <lim[1])], Fs)
ax4.clear()
ax4.plot(f[:np.where(f>50)[0][0]],Pxx_den[:np.where(f>50)[0][0]] )
ax1.callbacks.connect('xlim_changed', on_xlims_change1)
ax3.callbacks.connect('xlim_changed', on_xlims_change2)
plt.show()
What I'm seeking for is a way to update the ax2
and ax4
when the x axis
of the ax1
or ax3
is modified. each time the x axis
of ax1
or ax3
is modified I would like to compute the FFT only on the range of the curve displayed.
So I'm almost done to do this part. However because ax1
and ax3
have shared x axis. I was expecting that the two FFT plot should be updated But they don't.
So when I zoom in one temporal axis only the FFT directly to the rigth is updated and not all of them. I don't know where something is missing?