contourf 在 Matlab 中不显示彩色区域

countourf doesn't show colored regions in Matlab

为了让 countorf 显示颜色差异更大的区域,我应该在我的代码中更改什么?

clear all;
close all;
phi=90;
[xx,yy] = meshgrid(-20:0.1:20,-20:0.1:20);
Idontwantthis = (xx.^2+yy.^2)<0.1;
u = (xx./(xx.^2+yy.^2).^(3/2));
v = (yy./(xx.^2+yy.^2).^(3/2));
data= sqrt(u.^2+v.^2);
data(Idontwantthis)=NaN;
u(Idontwantthis)=NaN;
v(Idontwantthis)=NaN;
contourf(xx,yy,data,20);

首先,您不需要 meshgrid 超过 [-20 20]。尝试将范围缩小到喜欢 [-2 2]。在 运行 contourf 之后,更改颜色图:

clear all;
close all;
phi=90;

[xx,yy] = meshgrid(-2:0.01:2,-2:0.01:2);

Idontwantthis = (xx.^2+yy.^2)<0.1;
u = (xx./(xx.^2+yy.^2).^(3/2));
v = (yy./(xx.^2+yy.^2).^(3/2));
data= sqrt(u.^2+v.^2);
data(Idontwantthis)=NaN;
u(Idontwantthis)=NaN;
v(Idontwantthis)=NaN;

contourf(xx,yy,data,20);
colormap hsv;

这就是您的结果:

希望对您有所帮助!