繁体   English   中英

如何为某些点 plot 具有不同 colors 的网格(MATLAB)

[英]How to plot a grid with different colors for certain points (MATLAB)

问题

我有一个方形网格,尺寸为 NxN,网格点/节点之间的间距恒定。 我想 plot 这个网格,但有些点很特殊,希望它们以不同的颜色绘制。

期待

预期的 plot 应该是这样的,但有些块必须有不同的颜色!

在此处输入图像描述

代码

下面给出了我荒谬而缓慢的解决方案:

N = 80;
x = 1:1:N;
y = 1:1:N;

rx = randi([1 80],1,1000); %represents the x coordinates of the special points 
ry = randi([1 80],1,1000); %represents the y coordinates of the special points 

[X,Y] = meshgrid(x,y);
Z = zeros(80,80);
figure(1)
surf(X,Y,Z);

%Abandon surf, use scatter instead
figure(2)
for i=1:N
    for j=1:N        
        plot(x(i),y(j),'bo');
        hold on
    end
end

for i=1:1000
    plot(rx(i),ry(i),'ro');
    hold on    
end
grid on    

因为我的眼睛在流血,正确的做法是什么? 非常感谢。

颜色由 Z 控制。所以让 Z 成为不同的值。

linear_indx=sub2ind([N,N],rx,ry);
Z(linear_indx)=1;

更改一组不同的 colors 的颜色图(或自己制作)。 或使用surf(X,Y,Z,C)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM