【问题标题】:Programmatically producing polar or quasi-polar plots with a variable for color in matlab在matlab中以编程方式生成带有颜色变量的极坐标或准极坐标图
【发布时间】:2015-07-14 00:48:20
【问题描述】:

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

我发现的最佳方法似乎无法正常工作。运行以下代码:

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 将运行得非常快并且占用的内存最少。

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

【问题讨论】:

    标签: matlab plot polar-coordinates cartesian-coordinates


    【解决方案1】:

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

    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),您可以像设置二维图一样设置透视图。

    这是结果:


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

    Z = meshgrid(Data)';
    

    结果如下:

    【讨论】:

      【解决方案2】:

      根据 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);
      

      优雅,运行迅速,并产生美丽的人物。这是带有一些额外图表元素的输出示例:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-07
        • 2013-06-18
        • 2016-08-05
        • 1970-01-01
        相关资源
        最近更新 更多