如何在具有亮度的MATLAB中使用相位信息绘制复杂函数

时间:2016-06-09 14:13:08

标签: matlab plot visualization complex-numbers

我需要在MATLAB中用相位信息绘制复杂函数。为此,我绘制了一个冲浪图,其中x,y表示实部和虚部,高度表示幅度和颜色取决于相位,如下面的log(x)示例所示:

xmin=-5;
xmax=5;
dx=0.1;
xReal = xmin:dx:xmax;
xImaginary = xmin:dx:xmax;
[x,y] = meshgrid(xReal, xImaginary);
s = x + 1i*y;
z=log(s);
magnitude = abs(z1);
Phase = angle(z);
figure;
h(1) = surf(x,y,magnitude,Phase,'EdgeColor','none');
xlabel('Real');
ylabel('imaginary');
legend('Magnitude');

这是有效的,但情节的特征很难看到。我反而希望将函数的高度绘制为亮度。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

执行此操作的一种方法是使用magnitude值的倒数作为AlphaData,这将导致更高的值更亮(在其后面有白轴更透明)和更低的值变得更暗(更不透明)。

h = surf(x, y, zeros(size(magnitude)), 'EdgeColor', 'none');
set(h, 'FaceColor', 'flat', 'CData', Phase, 'FaceAlpha', 'flat', 'AlphaData', -magnitude);
view(2);

enter image description here

如果您有其他绘图对象并且不能依赖透明度,则可以手动将颜色与白色抖动。

% Determine the RGB color using the parula colormap
rgb = squeeze(ind2rgb(gray2ind(mat2gray(Phase(:))), parula));

% Normalize magnitude values
beta = magnitude(:) / max(magnitude(~isinf(magnitude)));

% Based on the magnitude, pick a value between the RGB color and white
colors = bsxfun(@plus, bsxfun(@times, (1 - beta), rgb), beta)

% Now create the surface
h = surf(x, y, zeros(size(magnitude)), 'EdgeColor', 'none');
set(h, 'FaceColor', 'flat', 'CData', reshape(colors, [size(magnitude), 3]));

话虽如此,我不确定这是否会让您更容易看到正在发生的事情。也许只考虑制作两个图,一个用于幅度,一个用于相位。

enter image description here