How to Add Border to Single Color Region in pcolor Plot
12 次查看(过去 30 天)
显示 更早的评论
I'm currently working with a pcolor plot in MATLAB, where the top-right side area is represented by a single color. I'm seeking assistance on how to draw a border around this particular region.
Attached are three figures:
Figure 1: The original pcolor plot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1634861/image.png)
I want the border coordinates for all '0' values extracted from my matrix, represented as coordinates in xc and yc variables. This will allow me to plot the border over the existing pcolor plot. The desired border appearance is illustrated below:
Figure 2: The plot needed.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1634886/image.png)
The data matrix of the variabel I am plotting looks of the form:
Figure 3: Screenshot data matrix
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1634871/image.png)
I have also attached data file for reference.
The code to display the plot:
[X,Y] = meshgrid(1:100,1:10); figure
h = pcolor(X',Y',medianVarianceAll2);
colormap(jet)
colorbar
%% If I obtain xc and yc variables, I should be able to execute:
[X,Y] = meshgrid(1:100,1:10); figure
h = pcolor(X',Y',medianVarianceAll2);
colormap(jet)
colorbar
hold on
plot(xc,yc,'linewidth',2,'r');
I'm looking for guidance on how to identify and outline the single color region in the plot. Any suggestions or code snippets would be greatly appreciated. Thank you in advance for your help!
0 个评论
采纳的回答
Voss
2024-3-4
load TestData
[m,n] = size(medianVarianceAll2);
[X,Y] = meshgrid(1:m,1:n);
figure
h = pcolor(X',Y',medianVarianceAll2);
colormap(jet)
colorbar
is_zero = medianVarianceAll2.' == 0;
Xz = X(is_zero);
Yz = Y(is_zero);
idx = boundary([Xz,Yz]);
[xc,yc] = stairs(Xz(idx),Yz(idx));
hold on
plot(xc,yc,'r','linewidth',2);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!