为什么 Matplotlib 的 plot_wireframe 的参数是二维数组? [英] Why are the arguments to Matplotlib's plot_wireframe two dimensional arrays?

查看:114
本文介绍了为什么 Matplotlib 的 plot_wireframe 的参数是二维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到对Matplotlib的plot_wireframe函数的X,Y和Z参数的清晰解释.我一直在玩他们提供的示例

我猜第一个维度是行号或函数号,第二个是点号.

解决方案

plot_wireframe(X,Y,Z)中, X 是x坐标,Y 是 y 坐标,Z 是 z 坐标.那些必须是2D阵列.原因是绘图功能需要一个二维网格.因此,(X [i,j],Y [i,j],Z [i,j])定义笛卡尔空间中的一个点.i,j 是网格索引.

现在的问题可能是,为什么我们需要 i,j 作为网格索引,而不能仅使用索引为 k 的单个一维网格,例如 X,Y,Z 是一维数组吗?
也就是说,因为在 (X[k], Y[k], Z[k]) 的情况下,关于哪个点与哪个其他点相邻的信息丢失了.在二维网格中,您可以明确地确定 (X[i,j], Y[i,j], Z[i,j]) 连接到(的邻居)(X [i + 1,j],Y [i + 1,j],Z [i + 1,j]),例如(X [i,j-1],Y [i,j-1],Z [i,j-1]).
在一维情况下,(X [k + 1],Y [k + 1],Z [k + 1])显然与(X [k],Y [k],Z [k]),但这仅给您两个连接,而线框中则需要4个连接.

I cannot find a clear explanation of the X, Y, and Z arguments to Matplotlib's plot_wireframe function. I have been playing with their provided example wire3d_demo.py but I don't get why X, Y, and Z are two dimensional arrays. It is a pretty curved 3D picture but if you look at the X, Y, and Z arrays they are all size 120 by 120 2D arrays. Matplotlib's documentation has this terse description: "Data values". Can anyone elaborate on that a little bit? I like Matplotlib but its documentation can be a little sparse.

Updating the question based on the answer. Maybe the first dimension of the 2D array represents a line in 3D space and the wireframe is constructed to connect up all of the lines. In this example I draw two quarter circles in the x,y plane with z coordinates 1.0 apart:

temp_x = []
temp_y = []
temp_z1 = []
temp_z2 =[]

import math
# x^2+y^2=4
for i in range(201):
    x = 0.01 * i
    temp_x.append(x)
    y = math.sqrt(4-(x*x))
    temp_y.append(y)
    temp_z1.append(0.0)
    temp_z2.append(1.0)

X=np.array([temp_x,temp_x])
Y=np.array([temp_y,temp_y])
Z=np.array([temp_z1,temp_z2])

# Plot a basic wireframe.
ax.plot_wireframe(X, Y, Z)

I guess the first dimension is line number or maybe function number and the second is point number.

解决方案

In plot_wireframe(X,Y,Z), X are the x coordinates, Y are the y coordinates and Z are the z coordinates. Those need to be 2D arrays. The reason is that the plotting function needs a 2D grid. Hence, (X[i,j], Y[i,j], Z[i,j]) defines a point in cartesian space. i,j are the grid indices.

Now the question might be, why do we need i,j as grid index, and cannot use a single 1D grid with an index k alone, such that X,Y,Z would be 1D arrays?
That is, because in the case of (X[k], Y[k], Z[k]) the information about which point lies next to which other point is lost. In the 2D grid, you can unambigously determine that (X[i,j], Y[i,j], Z[i,j]) is connected to (a neighbor of) (X[i+1,j], Y[i+1,j], Z[i+1,j]), as well as e.g. (X[i,j-1], Y[i,j-1], Z[i,j-1]).
In the 1D case, (X[k+1], Y[k+1], Z[k+1]) is clearly connected to (X[k], Y[k], Z[k]), but that gives you only two connections, while you need 4 connections in the wireframe.

这篇关于为什么 Matplotlib 的 plot_wireframe 的参数是二维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆