为什么我的散点图不旋转?

Why is my scatterplot not rotating?

我正在尝试创建一个二维高斯分布并将其旋转一定程度。

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 度。但是我看到了这个:

您的索引方式有误X1

目前,您将 X1[0]X1[:1] 作图,但 X1[:1]X1[0] 相同,正如您所说的 "all indices in the first dimension up to 1"(即 0) .

您只需要去掉冒号 - 即您需要绘制 X1[0]X1[1].

这个有效:

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