import numpy as np
import scipy as sp
import matplotlib.pyplot as plt


def sweep(x, sweep_time, fs):

    t = np.arange(0, sweep_time, 1 / fs)
    p = 20 * np.log10(abs(sp.fft(x)))
    f = np.linspace(0, fs / 2, len(p))
    plt.figure(1)
    plt.subplot(211)
    plt.plot(t, x)
    plt.grid()
    plt.subplot(212)
    plt.plot(f, p)
    plt.xscale('log')
    plt.grid()
    plt.show()

import numpy as np
import matplotlib.pyplot as plt


def sweep(x, sweep_time, fs):

    plt.subplots_adjust(hspace=0.4)
    t = np.arange(0, sweep_time, 1 / fs)
    p = 20 * np.log10(abs(np.fft.rfft(x)))
    f = np.linspace(0, fs / 2, len(p))
    plt.figure(1)
    plt.subplot(211)
    plt.plot(t, x)
    plt.grid()
    plt.xlabel('t / s')
    plt.ylabel('x(t)')
    plt.title('time domain')
    plt.subplot(212)
    plt.plot(f, p)
    plt.xscale('log')
    plt.grid()
    plt.xlabel('f / Hz')
    plt.ylabel('A / dB')
    plt.title('frequency domain')
    plt.show()

Add axis label and change import
Add axis label and change import

  import numpy as np
- import scipy as sp
  import matplotlib.pyplot as plt
  
  
  def sweep(x, sweep_time, fs):
  
+     plt.subplots_adjust(hspace=0.4)
      t = np.arange(0, sweep_time, 1 / fs)
-     p = 20 * np.log10(abs(sp.fft(x)))
+     p = 20 * np.log10(abs(np.fft.rfft(x)))
      f = np.linspace(0, fs / 2, len(p))
      plt.figure(1)
      plt.subplot(211)
      plt.plot(t, x)
      plt.grid()
+     plt.xlabel('t / s')
+     plt.ylabel('x(t)')
+     plt.title('time domain')
      plt.subplot(212)
      plt.plot(f, p)
      plt.xscale('log')
      plt.grid()
+     plt.xlabel('f / Hz')
+     plt.ylabel('A / dB')
+     plt.title('frequency domain')
      plt.show()
  
Add axis label and change import
## Code Before:
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt


def sweep(x, sweep_time, fs):

    t = np.arange(0, sweep_time, 1 / fs)
    p = 20 * np.log10(abs(sp.fft(x)))
    f = np.linspace(0, fs / 2, len(p))
    plt.figure(1)
    plt.subplot(211)
    plt.plot(t, x)
    plt.grid()
    plt.subplot(212)
    plt.plot(f, p)
    plt.xscale('log')
    plt.grid()
    plt.show()

## Instruction:
Add axis label and change import
## Code After:
import numpy as np
import matplotlib.pyplot as plt


def sweep(x, sweep_time, fs):

    plt.subplots_adjust(hspace=0.4)
    t = np.arange(0, sweep_time, 1 / fs)
    p = 20 * np.log10(abs(np.fft.rfft(x)))
    f = np.linspace(0, fs / 2, len(p))
    plt.figure(1)
    plt.subplot(211)
    plt.plot(t, x)
    plt.grid()
    plt.xlabel('t / s')
    plt.ylabel('x(t)')
    plt.title('time domain')
    plt.subplot(212)
    plt.plot(f, p)
    plt.xscale('log')
    plt.grid()
    plt.xlabel('f / Hz')
    plt.ylabel('A / dB')
    plt.title('frequency domain')
    plt.show()
