简体   繁体   English

当从 2d 过渡到 3d 时,z 值似乎映射到不正确的 x 和 y 值

[英]z values appear to be mapping to the incorrect x and y values when transition from 2d to 3d

i have a function that calculates az values based on given xy values in space.我有一个函数可以根据空间中给定的 xy 值计算 az 值。 I am trying to combine all the data together into a 3D grid however i noticed that the z values are not mapping correctly.我试图将所有数据组合到一个 3D 网格中,但是我注意到 z 值没有正确映射。 In other words when print the xyz and perform the calculation as a check in excel I do not get the right z values, but i'm confident my function is calculating correctly.换句话说,当打印 xyz 并在 excel 中执行计算作为检查时,我没有得到正确的 z 值,但我确信我的函数计算正确。 If i check it on an individual basis it gives the result i'm looking for.如果我单独检查它,它会给出我正在寻找的结果。 So i'm pretty sure the z values are getting mapped to the incorrect x,y.所以我很确定 z 值被映射到不正确的 x,y。

FYI the reason i need the grid together as XYZ is: once i get the function running i need to perform grid math on the resulting grid.仅供参考,我需要将网格作为 XYZ 一起使用的原因是:一旦我运行该函数,我需要对生成的网格执行网格数学运算。 For example i need to find certain locations based on a given X and Y and then find nodes that correspond to a certain z value and sum the area of the nodes...etc.例如,我需要根据给定的 X 和 Y 找到某些位置,然后找到对应于某个 z 值的节点并对节点的面积求和......等等。 I haven't gotten there yet obviously.我显然还没有到达那里。 I'm new to python and working my way there.我是 python 的新手并在那里工作。

What am I doing wrong here?我在这里做错了什么? Note I don't get any errors.注意我没有收到任何错误。

Any help is greatly appreciated.任何帮助是极大的赞赏。

What am i doing wrong?我究竟做错了什么?

import pandas as pd
import math
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.tri as tri
import matplotlib.pyplot as plt
from matplotlib import rcParams

#define the flow potential equation where X,Y is the injection well locations and x,y is the point of interest, Q is flow rate
def func(X, Y, x, y, Q):
    return (Q / (2 * np.pi)) * np.arctan((y-Y)/(x-X))

# necessary data
X1=2318743.658
Y1=797346.704
Q1=5
X2=2318690.718
Y2=797343.693
Q2=5
X3=2318715.221
Y3=797309.685
Q3=5

#initiate the XY grid - this will be a standard that will encompass all IW and MW
xi = np.linspace(2318675,2318800,625)
yi = np.linspace(797300,797375,375)

#mesh the grid in to x,y space
x,y = np.meshgrid(xi,yi)

#calculate the valus over the grid at every x,y using the defined function above
zi = (func(X1,Y1,x,y,Q1)+func(X2,Y2,x,y,Q2)+func(X3,Y3,x,y,Q3))

#reshape the xy space into 3d space
xy = np.array([[(x, y) for y in yi] for x in xi])

#reshape z into 3d space
z = np.array(zi).reshape(xy.shape[0],xy.shape[1], -1)

#combined xyz into a single grid
xyz = np.concatenate((xy, z), axis = -1)

I believe I was able to resolve the issue by changing this line of code:我相信我能够通过更改这行代码来解决这个问题:

xy = np.array([[(x, y) for y in yi] for x in xi])

to this:对此:

xy = np.array([[(x, y) for x in xi] for y in yi])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自 x、y、z 值的 matplotlib 2D 图 - matplotlib 2D plot from x,y,z values 在二维 Numpy 数组中查找值 x、y、z 的行 - Finding a row in 2d Numpy array with values x,y,z in python-将x,y,z值映射到2D表面数据 - python - map x, y, z values to 2D surface data Python-在2D网格上对x,y,z值进行装箱 - Python - Binning x,y,z values on a 2D grid 如何制作 3D plot(X,Y,Z),将 Z 值分配给 X,Y 有序对? - How to make a 3D plot (X, Y, Z), assigning Z values to X,Y ordered pairs? 从两个2D立体图像生成3D(x,y,z)点云 - Generating 3D (x,y,z) Point Clouds from Two 2D Stereo Images Python,Axes3D,绘图:无法附加到我的3D散点图中的X,Y,Z值列表 - Python, Axes3D, plotting: Cannot append to List of X,Y,Z values in my 3D scatterplot 在3D numpy对象中查找与给定z值对应的x和y值 - Finding x and y values corresponding to given z value in 3D numpy object 使用“索引”和“列”作为X,Y和值作为Z,将pandas DataFrame转换为3d图形? - Convert pandas DataFrame to a 3d graph using Index and Columns as X,Y and values as Z? Python:创建 X、Y 坐标和相应的计算 Z 值的网格以生成 XYZ 的 3D 数组 - Python: Creating a Grid of X,Y coordinates and corresponding calculated Z values to result in a 3D array of XYZ
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM