def f(x): return np.cos(2*np.pi*x) #represent noise from a data sample N = 150 p1 = np.linspace(0.00,0.3,15) p2 = np.linspace(0.32,0.4,40) p3 = np.linspace(0.42,1.2,45) xl = np.concatenate((p1,p2,p3)) np.random.seed(14) n1 = np.random.normal(0,0.3,15) n2 = np.random.normal(0,0.1,40) n3 = np.random.normal(0,0.3,45) noise = np.concatenate((n1,n2,n3)) y_measured = f(xl) + noise plt.figure(figsize=(6,3.5)) plt.plot(xl,f(xl),label='source function') plt.plot(xl,y_measured,'.',label='measured points') plt.legend() plt.show()