我已经创建了随机数据,并试图在散点图中添加抖动,但是我不知道如何为X和Y值应用抖动?我有X和Y形式的数据,但没有完整的数据将其传递给seaborn
绘图库。
def make_cubic_dataset(m, a=-3.0, b=1.0, c=3.5, d=4, mu=0.0, sigma=0.33):
x = np.random.uniform(low=-1.0, high=1.0, size=(m,))
y = a*x**3 + b*x**2 + c*x + d + np.random.normal(mu,sigma)
#generates a random number from the normal distribution with mu and sigma.
return (x,y)
np.random.seed(42)
x,y = make_cubic_dataset(100)
print(x.shape)
print(y.shape)
print(x[:5])
print(y[:5])
plt.scatter(x, y)
plt.title("Random Artificial Cubic dataset")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
输出:
预期输出
有人可以帮我吗?