Clear Filters
Clear Filters

How to Add Border to Single Color Region in pcolor Plot

12 views (last 30 days)
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.
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.
The data matrix of the variabel I am plotting looks of the form:
Figure 3: Screenshot data matrix
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!

Accepted Answer

Voss
Voss on 4 Mar 2024
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);

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!