问题
I need to plot a complex function with phase information in MATLAB. To do this I have ploted a surf plot with x,y representing real and imaginary, the height representing the magnitude and colour depending on the phase, as shown below for the example of 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');
This works, however features of the plot are very difficult to see. I'd desire instead to plot the height of the function as brightness. Is there a way to do this?
回答1:
One way to do this would be to use the inverse of the magnitude
value as the AlphaData
which would cause higher values to be lighter (more transparent with a white axes behind it) and lower values to be darker (more opaque).
h = surf(x, y, zeros(size(magnitude)), 'EdgeColor', 'none');
set(h, 'FaceColor', 'flat', 'CData', Phase, 'FaceAlpha', 'flat', 'AlphaData', -magnitude);
view(2);
If you have other plot objects and can't rely on transparency, you can instead manually dither the colors with white.
% 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]));
That being said, I'm not sure if this makes it any easier to see what is happening. Maybe consider just making two plots, one for the magnitude and one for the phase.
来源:https://stackoverflow.com/questions/37728440/how-can-i-plot-a-complex-function-with-phase-information-in-matlab-with-brightne