代码很简单的,主要注意一下选定某个子图就行,直接上代码了:
plt.figure(1)
ax1 = plt.subplot(2,1,1)
plt.sca(ax1) #选择ax1
plt.plot(a,b,linewidth=2,color='orange')
plt.xlabel('x', fontsize = 14)
plt.ylabel('y', fontsize = 14)
ax2 = plt.subplot(2,1,2)
plt.sca(ax2) #选择ax2
plt.bar(F,A,width=0.4,color='orange')
x=range(0,20,1)
plt.xlim(0,20)
plt.xticks(x)
plt.xlabel('Harmonic order')
plt.ylabel('Amplitude')
plt.savefig('FFT3',bbox_inches = 'tight',pad_inches = 0,dpi =350)