import numpy as np
import matplotlib.pyplot as plt
plt.fig = plt.figure(1)
plt.ax = plt.subplot(111)
x = np.linspace(0,2*np.pi,100)
# Function that modulates the amplitude of the sin function
amod_sin = lambda x: (1.-0.1*np.sin(25*x))*np.sin(x)
plt.ax.plot(x,np.sin(x),label = 'sin')
plt.ax.plot(x, amod_sin(x), label = 'modsin')
annot1=plt.ax.annotate('amplitude modulated\n curve', (2.1,1.0), (3.2,0.5), arrowprops={'width':2,'color':'k','connectionstyle':'arc3,rad=+0.5','shrink':0.05},verticalalignment='bottom', horizontalalignment='left', fontsize=10, bbox={'facecolor':'gray', 'alpha':0.1, 'pad':10})
annot2=plt.ax.annotate('corrupted data', (6.3,-0.5),(6.1,-1.1),arrowprops={'width':0.5,'color':'k','shrink':0.1},horizontalalignment='center', fontsize=10)
plt.ax.set_xticks(np.array([0,np.pi/2,np.pi,3/2*np.pi,2*np.pi]))
plt.ax.set_xticklabels(('$0$','$\pi/2$','$\pi$','$3/2 \pi$','$2\pi$'),fontsize=18)
plt.ax.set_yticks(np.array([-1.,0.,1]))
plt.ax.set_yticklabels(('$-1$','$0$','$1$'),fontsize=18)
axf = plt.ax.fill_between(x, np.sin(x), amod_sin(x), where=amod_sin(x)-np.sin(x) > 0,facecolor='gray')
plt.savefig('ex205.png', dpi=72)
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading