def plot_mag_phase(self, filename=None, plotpoints=10000, unwrap=False):
"""Produce a plot with magnitude and phase response in the same
figure. The y-axis on the left side belongs to the magnitude
response. The y-axis on the right side belongs to the phase
response
"""
unused_freq, mag = self.magnitude_resp(plotpoints)
freq, pha = self.phase_resp(plotpoints, unwrap=unwrap)
fig = plt.figure(1)
ax_mag = fig.add_subplot(111)
ax_pha = ax_mag.twinx()
ax_mag.semilogx(freq, mag, label='magnitude', color='red', linestyle='-')
ax_pha.semilogx(freq, pha, label='phase', color='blue', linestyle='--')
ax_mag.grid(True)
ax_mag.set_xlim(10, self.fs/2)
#ax_mag.set_ylim(bottom=-80) # FIXME: ad proper padding
#ax_mag.margins(0.1)
ax_mag.set_title('Frequency response')
ax_mag.set_xlabel('Frequency [Hz]')
ax_mag.set_ylabel('Magnitude [dB]')
ax_pha.set_ylabel('Phase [deg]')
handles1, labels1 = ax_mag.get_legend_handles_labels()
handles2, labels2 = ax_pha.get_legend_handles_labels()
plt.legend(handles1 + handles2, labels1 + labels2, loc='best')
if filename is None:
plt.show()
else:
try:
plt.savefig(filename)
finally:
plt.close(1)
评论列表
文章目录