相关疑难解决方法(0)

当指定facecolors时,Edgelines在mplot3d冲浪中消失

我在matlab中生成了以下表面图:

Matlab图

我需要在.NET中创建它.我希望使用IronPython来做到这一点.但首先我只想尝试用Python创建绘图(PyLab).这是我到目前为止:

Python图

请看看我的代码并告诉我如何让python显示黑色边缘线.当我添加facecolors=UWR(heatmap)属性时,它们似乎消失了surf(...).这是mplot3d中的错误还是设计?无论哪种方式,我如何让线路回来?

这是我的代码(大数据矩阵的道歉):

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import matplotlib
from pylab import *
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')

#Sample colour data
heatmap = np.array([(0.304, 0.288,  0.284,  0.26,   0.248,  0.224,  0.204,  0.184,  0.18,   0.18,   0.156,  0.148,  0.144,  0.136,  0.136,  0.128,  0.124,  0.124,  0.128,  0.124,  0.124),
                    (0.356, 0.348,  0.332,  0.328,  0.308,  0.292,  0.288,  0.272,  0.252,  0.232,  0.216,  0.204,  0.16, …
Run Code Online (Sandbox Code Playgroud)

python matplotlib python-2.7 mplot3d

6
推荐指数
1
解决办法
2750
查看次数

生成2D数组的梯度图

我有一个2D数组,它存储每个点的属性值作为其元素: f(x,y) = f[x][y].现在我想找到这个数组的渐变.我调查np.gradient但它只给出了两个数组作为返回,首先是x方向的导数,y方向的第二个.

我想学习如何使用这个或任何其他方式创建一个梯度图,显示2D数组的渐变变化.
varray是我想要创建渐变映射的2D数组.以下是我现在唯一能想到的事情.我知道应该有聪明的方式来使用x gradienty gradient生成np.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()  
Run Code Online (Sandbox Code Playgroud)

我想基本上从第一张图片中得到第二张图片.第二幅图像描述为? = \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()  
Run Code Online (Sandbox Code Playgroud)

我得到的图像: 在此输入图像描述

我从对等式的基本理解中解释了这个错误?

所以这是我的图像.左侧:初始2D地图的图像.右:梯度图的图像.@Mad物理学家你认为他们与上面的相似只有不同的颜色?

在此输入图像描述 在此输入图像描述

python numpy

5
推荐指数
1
解决办法
7321
查看次数

如何创建 4D 复杂曲面图?

我有以下 Matlab 代码,我想将其转换为 Python 3 代码。

r = (0:1:15)';                           % create a matrix of complex inputs
theta = pi*(-2:0.05:2);
z = r*exp(1i*theta);
%w = z.^(1/2)  ;                          % calculate the complex outputs
w = sqrt(r)*exp(1i*theta/2);

figure('Name','Graphique complexe','units','normalized','outerposition',[ 0.08 0.1 0.8 0.55]);
subplot(121)

surf(real(z),imag(z),real(w),imag(w))    % visualize the complex function using surf
xlabel('Real(z)')
ylabel('Imag(z)')
zlabel('Real(u)')
cb = colorbar;
colormap jet;                            % gradient from blue to red
cb.Label.String = 'Imag(v)';

subplot(122)
surf(real(z),imag(z),imag(w),real(w))    % visualize the complex function using surf
xlabel('Real(z)')
ylabel('Imag(z)')
zlabel('Imag(v)')
cb = …
Run Code Online (Sandbox Code Playgroud)

python 3d matlab matplotlib

1
推荐指数
1
解决办法
229
查看次数

标签 统计

python ×3

matplotlib ×2

3d ×1

matlab ×1

mplot3d ×1

numpy ×1

python-2.7 ×1