我有一个二维数组存储每个点的属性值作为其元素:f(x,y) = f[x][y]
。现在我想找到这个数组的渐变。我看着np.gradient
,但它只是给出了两个数组作为返回,首先是x方向的导数和y方向的第二数组。生成二维数组的梯度图
我想了解如何使用此方法或任何其他方式创建显示2D数组梯度变化的梯度图。
varray
是我想创建梯度图的二维数组。以下是我现在可以考虑的唯一事情。我知道应该有巧妙的方法来使用由np.gradient()
生成的x gradient
和y gradient
,但我想不起来。 lx
和ly
是2D阵列的x和y维度。
vgrad = np.gradient(varray)
xgrad = vgrad[0]
x, y = range(0, lx), range(0,ly)
xi, yi = np.meshgrid(x, y)
rbf = scipy.interpolate.Rbf(xi, yi, xgrad)
plt.imshow(v, vmin = np.amin(xgrad), vmax=np.amax(xgrad))
plt.colorbar()
plt.show()
我想基本上从第一个图像获得第二个图像。第二张图像被描述为σ = \alpha*grad(varray)
。
使用下面@Mad Physicist所建议的梯度幅度。
vgrad = np.gradient(varray)
fulgrad = np.sqrt(vgrad[0]**2 + vgrad[1]**2)
plt.imshow(fulgrad,cmap=plt.get_cmap('hot'), vmin = np.amin(fulgrad),vmax = np.amax(fulgrad))
plt.colorbar()
plt.show()
我解释这个错误来自方程的基本的了解?
所以这里是我的图片。左图:初始2D地图的图像。在右边:梯度图的图像。 @Mad Physicist你认为他们是否与上面类似,只有颜色差异?
你能向我们展示的情节你正在寻找与您的数据来创建类型的例子吗?例如,你想要一个流线图吗? http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.streamplot – ballsatballsdotballs
你只需要使用不同的颜色映射。你得到的图像很好。选择确切的颜色图可能有点困难。最初的预期图像是如何产生的? –
嘿@ballsatballsdotballs,我添加了我从剧情中寻找的东西。最初的情节和情节之后。 –