【发布时间】:2019-04-12 10:27:38
【问题描述】:
我有一个坐标数组。我计算所有点之间的距离。现在我只想显示距离超过某个阈值的坐标。我如何在 python 中做到这一点?
import numpy as np
import scipy
import matplotlib.pylab as plt
dx = np.array([b-a for a,b in combinations (x,2)])
dy = np.array([b-a for a,b in combinations (y,2)])
all_distances = scipy.stats.pdist( np.array(list(zip(x,y))) )
all_distances
df3=all_distances[~(all_distances<=35)]
df4=all_distances[~(all_distances<=40)]
df5=all_distances[~(all_distances<=45)]
fig, ax = plt.subplots()
plt.scatter(df3)
plt.ylabel('dy')
plt.xlabel('dx')
plt.show()
您在下面看到所有距离的点,但现在我想要一个散点图,其点高于 35 的阈值
【问题讨论】:
-
您能否提供一个包含所有导入和一些数据的最小工作示例?
-
是的,我添加了散点图
-
你能说一下 x 和 y 的 10 个值,其中 5 个应该绘制,5 个不应该绘制吗?
-
如果你有 10 个 x 和 y 的值。您有 45 对具有一定距离和 dx/dy 坐标。现在我想跳过低于或高于一定距离的对并绘制它们的 dx/dy 点。我该怎么做?
-
如果 dx 和 dy 的长度与 all_distances 相同,您可以执行 plt.scatter(dx[all_distances>35], dy[all_distances>35])