【问题标题】:How to get new list of points after threshold distance?如何在阈值距离后获得新的点列表?
【发布时间】: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 的阈值

scatterplot

【问题讨论】:

  • 您能否提供一个包含所有导入和一些数据的最小工作示例?
  • 是的,我添加了散点图
  • 你能说一下 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])

标签: python distance threshold


【解决方案1】:

你可能正在寻找这样的东西

import numpy as np
from scipy.spatial.distance import pdist

combinations = np.array([(1,2), (3,4), (5,8), (10,12)])

all_distances = pdist( np.array(combinations))
print(all_distances)
print(all_distances[all_distances>3])

你可以对其他数组做同样的事情,所以可能像plt.scatter(dx[all_distances&gt;35], dy[all_distances&gt;35]) 这样的东西可以解决你的问题。

【讨论】:

  • 查看散点图。没有绘制所有节点对(每个点都有 dx 和 dy 值)。现在我只想绘制距离 > 35 的节点对。我该如何解决这个问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-05
  • 2018-01-12
  • 2020-01-12
  • 1970-01-01
  • 1970-01-01
  • 2018-11-17
  • 1970-01-01
相关资源
最近更新 更多