def plot_reflection_factor(self, filename=None):
        """
        Plot reflection factor.
        """
        
        if self.frequency is None:
            raise ValueError("No frequency specified.")
        if self.angle is None:
            raise ValueError("No angle specified.")
        
        try:
            n_f = len(self.frequency)
        except __HOLE__:
            n_f = 1
        try:
            n_a = len(self.angle)
        except TypeError:
            n_a = 1
        
        
        if n_f==1 and n_a==1:
            raise ValueError("Either frequency or angle needs to be a vector.")
        
        elif n_f==1 or n_a==1:
            if n_f==1 and n_a>1:# Show R as function of angle for a single frequency.
                xlabel = r"$\theta$ in degrees"
            elif n_f>1 and n_a==1:# Show R as function of frequency for a single angle.
                xlabel = r"$f$ in Hz"
            R = self.reflection_factor
            fig = plt.figure()
                
            ax0 = fig.add_subplot(211)
            ax0.set_title("Magnitude of reflection factor")
            ax0.semilogx(self.frequency, np.abs(R))
            ax0.set_xlabel(xlabel)
            ax0.set_ylabel(r'$\left|R\right|$') 
            ax0.grid()
            
            ax1 = fig.add_subplot(212)
            ax1.set_title("Phase of reflection factor")
            ax1.semilogx(self.frequency, np.angle(R))
            ax1.set_xlabel(xlabel)
            ax1.set_ylabel(r'$\angle R$') 
            ax1.grid()

            
        elif n_f>1 and n_a>1:# Show 3D or pcolor
            R = self.reflection_factor
            fig = plt.figure()
            
            #grid = AxesGrid(fig, 111, nrows_ncols=(2, 2), axes_pad=0.1, cbar_mode='each', cbar_location='right')
            ax0 = fig.add_subplot(211)
            #ax0 = grid[0]
            ax0.set_title("Magnitude of reflection factor")
            ax0.pcolormesh(self.frequency, self.angle * 180.0 / np.pi, np.abs(R))
            #ax0.pcolor(self.angle, self.frequency, np.abs(R))
            #ax0.set_xlabel(xlabel)
            #ax0.set_ylabel(r'$\left|R\right|$') 
            ax0.grid()
            
            ax1 = fig.add_subplot(212)
            #ax1 = grid[1]
            ax1.set_title("Phase of reflection factor")
            ax1.pcolormesh(self.frequency, self.angle * 180.0 / np.pi, np.angle(R))
            #ax1.pcolor(self.angle, self.frequency, np.angle(R))
            #ax0.set_xlabel(xlabel)
            #ax0.set_ylabel(r'$\angle R$') 
            ax1.grid()

        else:
            raise RuntimeError("Oops...")
        
        #plt.tight_layout()
        
        if filename:
            fig.savefig(filename, transparant=True)
        else:
            return fig
dataset/ETHPy150Open python-acoustics/python-acoustics/acoustics/reflection.py/Boundary.plot_reflection_factor