python - How to add Jitter to scatter plot with X and Y values?
问题描述
I have created random data and trying to add jitter in scatter plot but I can't figure out how to apply jitter for the X and Y values? I have data in the form of X and Y but not the whole as a data to pass it to the seaborn
plotting library.
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()
Output:
Expected output
Can anyone help me with this?
解决方案
推荐阅读
- android - 如何用 Litho 替换现有文本?
- swift - 从 json 中获取数据并显示在选择器中
- excel-formula - 如何在不使用 MINIFS 的情况下在 excel 中获得以下结果?
- c# - 为什么我在 Visual Studio 中单击“添加项目”时没有 ADO.NET?
- trace32 - 函数T32_GetBreakpointList的python实现
- php - 通过 websocket 服务器从 http 访问的 PHP 发送数据
- kendo-ui - 创建新记录在 Jquery Kendo 子网格中不起作用
- javascript -
- javascript - 在 javascript 中检查 xsi:null: true
- ruby-on-rails - 在 Rails 应用程序的公共文件夹中访问“环境变量”