max_points = len(x)
# Assuming you only want 50 points.
random_indexes = random.sample(range(max_points), 50)
new_x = [x[i] for i in random_indexes]
new_y = [y[i] for i in random_indexes]
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
# Pick random 10 samples, 2 means two choices from [0, 1] for the mask
subsample = np.random.choice(2, 10).astype(bool)
plt.scatter(x[subsample], y[subsample])
plt.show()
您可以使用
然而,这让结果有点取决于随机运气。我们可以通过making a heatmap做得更好。^{} 使这一点特别容易:
^{pr2}$下面是一个比较这两种方法的示例:
{1美元^
您可以使用random.sample():
可以使用随机索引掩码从
x
和y
中随机选取或者,您可以使用
^{pr2}$hist2d
来绘制二维直方图,它使用密度而不是数据点相关问题 更多 >
编程相关推荐