在 matlab 中以编程方式生成带有颜色变量的极坐标或准极坐标图

Programmatically producing polar or quasi-polar plots with a variable for color in matlab

我想使用 matlab 创建图表,以径向方式表示质量的数值评估。

我找到的最好的方法似乎不能正常工作。一个 运行s 以下代码:

theta = (0 : (360/11) : 360)*pi/180;
r = 0 : 2 : 20 ;
[TH,R] = meshgrid(theta,r);
[X,Y] = pol2cart(TH,R);
Z = meshgrid(Data);
surf(X,Y,Z);

Data 是一个包含 11 个数字的数据向量,示例数据集如下:

Data = 0.884, 0.882, 0.879, 0.880, 0.8776, 0.871, 0.8587, 0.829, 0.811, 0.803, 0.780 

这里 surf 的输出是这样的:

我想制作此类图像的更精致版本:

我用以下代码生成的:

for theta = 0 : pi/100 : pi;  
    v = [InterpolatedImageHeight;LengthVector];
    x_center = InterpolatedImageHeight((HorizontalRes+1)/2);
    y_center = 0; %InterpolatedImageHeight((HorizontalRes+1)/2);
    center = repmat([x_center; y_center], 1, length(InterpolatedImageHeight));
    R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
    vo = R*(v - center) + center;
    x_rotated = vo(1,:);
    y_rotated = vo(2,:);
    scatter(x_rotated,y_rotated,DotSize,InterpolatedData,'filled'); %x,y,area,color,properties
end

问题是它是一个散点图,我基本上使用 plot(r,Data),绘制许多副本,并增加点的大小。图形本身有很多接缝,这会占用大量内存,并且是时间密集型的,其中 surfmesh 将 运行 非常快并占用最少的内存。

如何生成具有可变颜色输入的同心环?

你的问题中有两个完全不同的情节。第一个将数据表示为从原点向圆外的射线。数据点逆时针放置。一个改进的版本可以这样实现:

Data = [0.884, 0.882, 0.879, 0.880, 0.8776, 0.871,...
        0.8587, 0.829, 0.811, 0.803, 0.780]; 

theta = linspace(0,2*pi,length(Data));
r = linspace(0,20,length(Data));
[TH,R] = meshgrid(theta,r);

Z = meshgrid(Data);
[X,Y,Z] = pol2cart(TH,R,Z);

surf(X,Y,Z);
view(2);
shading interp

请注意,我使用 linspace 生成 thetar 以始终匹配 Data 的长度。 Z 也通过 pol2cart 传递。然后你可以使用 shading interp 删除补丁之间的线条并插入颜色。使用 view(2),您可以像设置 2d 图一样设置视角。

这是结果:


获得第二个示例中的结果相对容易。那里的数据点代表原点周围的同心圆,并从原点向外放置。因此,只需使用以下行转置 Z 的网格:

Z = meshgrid(Data)';

这是当时的结果:

根据 Darren Rowland 在 this thread 中的代码,我提出了以下解决方案:

x = interp1(1:length(data),datax,(datax(1):datax(end)/f:datax(end)),'linear'); 
y = interp1(1:length(datay),datay,datay(1):datay(end)/f:datay(end),'spline');
theta = linspace(0,2*pi,n);

xr = x.'*cos(theta);
zr = x.'*sin(theta);
yr = repmat(y.',1,n);

figure;
surf(xy,yr,zr,zr*numcolors);

优雅,跑得快,身材漂亮。这是带有一些额外图表元素的输出示例: