[英]python - map x, y, z values to 2D surface data
I have the following data set: 我有以下数据集:
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
x
and y
is the location of the sample data point on a 2D surface. x
和y
是2D曲面上样本数据点的位置。 z
is the value of the data sample at the location. z
是该位置的数据样本的值。
Essentially I want something something like this: 本质上,我想要这样的东西:
However, as you can see, z
values are not yet mapped into 2D grid format. 但是,如您所见,
z
值尚未映射为2D网格格式。
This is NOT what I want: 这不是我想要的:
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
All the examples I found online calculates z
matrix assuming some contour plot, but that's not the case for me. 我在网上找到的所有示例都在假设一些轮廓图的情况下计算
z
矩阵,但对我而言并非如此。 In my case, z
is 1D array that contains the, say, gold percentage of a rock at the sample locations, and x
and y
accounts for the location of that sample. 在我的情况下,
z
是一维数组,包含样本位置岩石的金百分比,而x
和y
说明该样本的位置。
How can I convert the z
array into 2D matrix that accounts for the location of the sample? 如何将
z
数组转换为用于说明样本位置的2D矩阵?
At the end, I want to make a scatter plot using the 2D transformed_z
matrix. 最后,我想使用2D
transformed_z
矩阵绘制散点图。
random_sample = transformed_z[x,y]
ax.scatter(y,x,c=transformed_z, cmap=im.cmap, norm=im.norm)
IIUC you just want to plot the values in z
as a color coded scatterplot with x
and y
as coordinates. IIUC您只想将
z
的值绘制为以x
和y
为坐标的色标散点图。
You do not need to transform z for this purpose, this can be done purely with the given three arrays as they are: 您不需要为此而变换z,这可以纯粹使用给定的三个数组来完成:
import matplotlib.pyplot as plt
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
plt.figure()
plt.scatter(x, y, c=z, cmap='Wistia')
cb = plt.colorbar()
cb.set_label('gold percentage of a rock (%)')
plt.xlabel('X')
plt.ylabel('Y')
for xt, yt, zt in zip(x, y, z):
plt.text(xt, yt+1, str(zt), ha='center')
I've added the values as text for faster comparison with the arrays. 我将这些值添加为文本,以便与数组进行更快的比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.