2015-09-07 22 views
0

我想创建一个2D高斯分布,并在一定程度上旋转它。为什么我的散点图不旋转?

import numpy as np 
import matplotlib.pyplot as plt 

x = np.random.normal(0, 15, 5000) 
y = np.random.normal(0, 3, 5000) 

X = np.array([x, y]) 
print X.shape 

angle = 28 
theta = np.pi * angle/180 

rotation = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]]) 
X1 = np.dot(rotation, X) 
print X1.shape 

fig = plt.figure(figsize=(16, 8)) 
fig.add_subplot(2, 1, 1).scatter(x, y) 
fig.add_subplot(2, 1, 2).scatter(X1[0], X1[:1]) 

plt.show() 

我希望看到什么这里是高斯第一散点图,然后第二个几乎一样,但通过28度旋转。而是我看到这一点:

enter image description here

+0

汤姆的答案是正确的。如果您对绘制双变量分布的其他方式感兴趣,请参阅https://geonet.esri.com/blogs/dan_patterson/2015/06/16/before-i-forget-8-bivariate-distribution – 2015-09-07 15:56:36

回答

2

你只需要在你的方式指数X1错误。

目前,您绘制X1[0]X1[:1],但X1[:1]是一样的X1[0],因为你说“的第一维度的所有指标高达1”(即0)。

你只需要摆脱冒号 - 即你需要绘制X1[0]X1[1]

这工作:

fig.add_subplot(2, 1, 2).scatter(X1[0], X1[1]) 

enter image description here

相关问题