- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个未均匀采样的 gps 坐标的 xy 数组。这似乎很明显,但我想将它投影到网格上。这是我的上下文脚本:
import numpy as np
from matplotlib.mlab import griddata
gps_track = np.array([[0,0],[1.2,2.3],[1.9,3],[3.2,4.3],[4,2.9],[6.5,3.1]])
x = gps_track[:,0]
y = gps_track[:,1]
# define grid
binsize = 1
xmin, xmax = x.min(), x.max()
ymin, ymax = y.min(), y.max()
xi = np.arange(xmin, xmax+binsize, binsize)
yi = np.arange(ymin, ymax+binsize, binsize)
在给定 (x, y) 原始坐标的情况下,我如何从这里开始获取在 (xi, yi) 网格上插值的 (xnew, ynew) 值?
# grid the data
xnew, ynew = grid(x, y, xi, yi)
我想我会使用类似于 matplotlib 函数 griddata 的东西:
zi = griddata(x, y, z, xi, yi)
我做不到;我想对坐标本身进行网格化,而不是对值 z = f(x,y) 进行网格化。您知道有什么快速解决方案可以做到这一点吗?
编辑:这真的很有帮助。你们好棒!为了更准确地满足我的要求,我采用了您生成的图并用空心圆圈标记了我希望获得的 (xnew, ynew) 样本。它们落在 (xi, yi) 网格上。
最佳答案
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as interpolate
gps_track = np.array([[0,0],[1.2,2.3],[1.9,3],[3.2,4.3],[4,2.9],[6.5,3.1]])
x = gps_track[:,0]
y = gps_track[:,1]
binsize = 1.0
xmin, xmax = x.min(), x.max()
ymin, ymax = y.min(), y.max()
xi = np.arange(xmin, xmax+binsize, binsize)
yi = np.arange(ymin, ymax+binsize, binsize)
N = 1000
tckp, u = interpolate.splprep([x, y], s=0, k=2, nest=-1)
xx, yy = interpolate.splev(np.linspace(0, 1, N), tckp)
# find integer indices where the xx fall between xi values
x_idx = np.searchsorted(xi, xx)
# find where the x_idx indices change. This is where the curve crosses a grid line
x_mask = np.diff(x_idx) != 0
# do the same for y
y_idx = np.searchsorted(yi, yy)
y_mask = np.diff(y_idx) != 0
fig, ax = plt.subplots()
line, = ax.plot(xx, yy)
ax.scatter(xx[x_mask], yy[x_mask], color='red')
ax.scatter(xx[y_mask], yy[y_mask], color='red')
# make sure the grid lines fall on xi and yi
ax.set_xticks(xi)
ax.set_yticks(yi)
ax.grid()
plt.show()
产量
xi
, yi
定义你的网格。
xx
, yy
是插值路径上的点。
要查找垂直网格线上的点,首先使用np.searchsorted
查找索引(xi
),其中xx
(x 数据)中的每个值都适合排序数组 xi
(网格)。
In [88]: x_idx = np.searchsorted(xi, xx)
In [89]: x_idx
Out[89]:
array([0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 7, 7, 7, 7])
然后我们可以取相邻值的差值:
In [91]: np.diff(x_idx)
Out[91]:
array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0])
非零值表示路径已经穿过网格线。
In [93]: x_mask = (np.diff(x_idx) != 0)
In [94]: x_mask
Out[94]:
array([ True, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, True, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, True, False, False, False, False, False, False,
False, False, False, False, False, False, False, True, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
True, False, False, False, False, False, False, False, False,
False, False, False, False, True, False, False, False, False,
False, False, False, False, False, True, False, False, False], dtype=bool)
然后可以使用 x_mask
找到插值上的点的 x 值最接近网格线的路径:
In [95]: xx[x_mask]
Out[95]:
array([ -6.93660834e-18, 9.65180188e-01, 1.95810449e+00,
2.94969940e+00, 3.94167195e+00, 4.92607812e+00,
5.99593850e+00])
当然我们可以类似地找到相应的 y 值:
In [96]: yy[x_mask]
Out[96]:
array([ 0. , 2.02032307, 3.06460807, 4.25374305, 2.97366674,
2.4770819 , 2.79951527])
上面我已经介绍了用于查找垂直网格线交叉点的步骤;在代码中,水平网格线也是如此。
关于python - 如何粗化xy坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680973/
我正在尝试使用 (X,Y) 形式的 XY 点数组中的三个 XY 点找到最大面积。 我目前收到错误 called object type 'double' is not a function or fu
我在屏幕上设定的 XY 位置(例如 x=100,y=200)有一个点 (A),在屏幕上随机的 XY 位置(例如 x=50)有另一个点 (B) , y = 50)。 我想沿直线将点 B 移向点 A。 如
在我的项目中,每次打开 JSP 时我都必须分配一个变量。我用小脚本试过了 在 JSP 和 EL 中 ${}返回变量。 但是好像不行。 korrekteAntwort=${}后出现错误, 难道不
这个问题在这里已经有了答案: Bind and Destructure block arguments (3 个答案) 关闭 4 年前。 鉴于以下内容目前在 Ruby 中的工作方式类似于 Haske
#include int main(double x, double y, double x1, double y1, double x2, double y2) { // First co
我有一个函数可以根据任意数量的字典(每个字典代表图表上的一条线)生成 XY 散点图,每个字典都包含一个日期键和一个数值。到目前为止,这些值似乎在 Y 轴上有效,但日期轴 (X) 似乎已损坏。每次我从字
尝试绘制一个 xy 散点图,其中 z 值由 xy 点的颜色表示。 数据: 1.1, 32.27, 19.4 1.2, 21.34, 18 1.4, 47.45, 19.4 R代码: inp <-
我有以下代码: var favourites = JSON.parse(localStorage.getItem("favourites")); Service.all().then(function
我确实在对齐 rec 标签中的文本时遇到问题。遵循代码和两张描述案例的图片。 HTML: DACH 我确实想将文本左对齐到 rect-tag 的开头。附件是来自 Debug模式的图片,
我在 MATLAB 中有一个 x-y 散点图,想在每个点上放置一个数据标签。我似乎无法在文档中找到它。可能吗? 最佳答案 例子: p = rand(10,2); scatter(p(:,1), p(:
本文整理了Java中com.androidplot.xy.YValueMarker类的一些代码示例,展示了YValueMarker类的具体用法。这些代码示例主要来源于Github/Stackoverf
本文整理了Java中com.androidplot.xy.ZoomEstimator类的一些代码示例,展示了ZoomEstimator类的具体用法。这些代码示例主要来源于Github/Stackove
我花了很多时间寻找它,但找不到。如果这是一个基本问题,请不要轰炸我:) 我想用以下向量生成散点图 > x [1] "a" "b" "c" "d" > y [1] 5 6 3 4 我使用了 xyplot
这似乎微不足道 R问题,但我没有找到任何令人信服的解决方案。我想翻转 X 轴变为 Y 的图,反之亦然。在箱线图中有一个 horiz="T"选项,但不在 plot() 中. 这是我的情节: plot(r
This问题解释了如何在特定位置添加网格 点阵图(即相当于 两个 abline() 用于正常绘图)。我的问题是当 我尝试添加一个常规网格(相当于调用 grid() 对于正常情节)......情节的内容
我正在寻找创建 xy 图的 GWT api/示例。这是我在 powerpoint 中制作的示例图片。将有另外两个图,如下例所示,每个点都可以点击,然后在另一个图上突出显示。有没有办法在 GWT 中使用
我想将两个时间序列图表放置在彼此之上共享相同的时域轴,都具有多个数据集。 chart1 = ChartFactory.createTimeSeriesChart("", "", "", tsc1, t
我绘制了以下内容: t = data.frame(Sample=c('1','1','1','2','2','2'), X=c(12,13,14,12,11,15), Y=c(4,3,5,1,2,3)
我有一个 CAD 应用程序,我正在尝试为其构建插件,并且我需要能够选择直线和圆弧。我不能直接从应用程序中执行此操作。在我的代码中,我想开始用鼠标徒手绘制一个窗口矩形。通过 API,我可以确定刚刚绘制的
我想将 2 个变量的函数值显示为“位图”图像,例如 x+y。所以我尝试了这个,基于 http://gnuplot.sourceforge.net/demo/heatmaps.html : # Colo
我是一名优秀的程序员,十分优秀!