How to match colors of an extracted contour with the colors of the main figure?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
University
il 5 Feb 2024
Commentato: University
il 5 Feb 2024
I extracted the region for activity, xi = linspace(58, 115) and l=(1.24787e-06, 2.42592e-06) from the figure attached, which is represened by the red and yellow colors. Please how can I set colormap colors for the extracted figure to be the same colors (red and yellow) as the figure main(attached figure)? The code for the main plot is given below:
figure;
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
0 Commenti
Risposta accettata
Cris LaPierre
il 5 Feb 2024
Modificato: Cris LaPierre
il 5 Feb 2024
colormaps by default cover the range of data in your figure. You will want to manually set the color limits in the extracted figure to match the original figure so that the color is scaled the same.
In the original figure, extract the limits using lims = clim
In the new figure, apply the same limits using clim(limits)
Z = peaks;
[M,c]=contourf(Z);
colormap jet
colorbar
hold on
rectangle('Position',[17 31 15 15])
hold off
lims = clim
If you do not modify clim, the colors still go from dark blue to dark red
figure
contourf(Z(31:46,17:32))
colormap jet
colorbar
Set clim so the color range in the cropped figure is the same as the original.
figure
contourf(Z(31:46,17:32))
colormap jet
clim(lims)
colorbar
You will notice that, unless otherwise specified, contourf also sets the number of contour levels automatically. Use the properties of the original contour plot to apply the same levels here.
figure
contourf(Z(31:46,17:32),c.LevelList)
colormap jet
clim(lims)
colorbar
6 Commenti
Cris LaPierre
il 5 Feb 2024
I would use logical indexing of xi and L. You need to define both rows and columns. Note in the original sample you shared, it appears your Y values are in the wrong scale: intul(6.63544e-11:7.55125e-11, 1.12279e-10:1.34579e-10)
load sample1.mat
figure;
xi = linspace(0, 120,20);
L=linspace(2e-08, 6.66666666666667e-06, 20);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
colormap jet
clabel(C,h)
hold on
[XX,YY] = meshgrid(L,xi);
plot(XX,YY,'w.','MarkerSize',5)
rectangle('Position',[0.5e-6 50 2.5e-6 60])
hold off
% Capture color limit
lims = clim;
% Figure around the isolated maximum
fig6 = figure(6);
Ln = L(L>=0.5e-6 & L<=3e-6);
xin = xi(xi>=50 & xi<=110);
% for an array, rows = y, cols = x
contourf(Ln,xin,intul(xi>=50 & xi<=110,L>=0.5e-6 & L<=3e-6),h.LevelList,'ShowText','off','edgecolor','none')
colormap jet
clim(lims)
colorbar
There is a little difference here because the actual values chosen do not exactly align with the value in L and xi.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Colormaps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!