import matplotlib.pyplot as plt import numpy as np # Create some data for the top subplot x = np.linspace(0, 10, 100) y = np.sin(x) + np.random.normal(0, 0.5, 100) + np.sin(2*x) + np.random.normal(0, 0.5, 100) + np.sin(3*x) + np.random.normal(0, 0.5, 100) # Create the figure and top subplot fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 6), sharex=True) ax1.plot(x, y, '-', label='Original signal') ax1.set_title('Original signal with noise') ax1.legend() # Create the bottom subplot with the smooths widths = [2, 5, 10] styles = [':', '--', '-.'] colors = ['r', 'g', 'b'] for i, width in enumerate(widths): y_smooth = np.convolve(y, np.ones(width)/width, mode='same') ax2.plot(x, y_smooth, styles[i], color=colors[i], label='Smooth width = {}'.format(width)) ax2.set_title('Smoothed signals') ax2.legend() # Show the plot plt.show()