How to add a patch to a plot of data?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a plot of Data (wavelength vs transmission) and I was to highlight sections on the plot independent of y axis. Imagine highlighting certain wavelengths along the x axis. I think I need to use a patch function but not sure how to define the rectangle shape ontop of the existing data plot and get it to match.
0 commentaires
Réponses (1)
Star Strider
le 26 Fév 2022
I am not certain what your function or data are or what you want to plot.
See if this helps to cliarify the general approach —
x = linspace(0, 10, 500);
y = sin(2*pi*x/5);
idx = find(diff(sign(y-0.5))) % Regions Greater Than 0.5
idxm = reshape(idx,2,[])
figure
plot(x, y)
yl = ylim;
hold on
for k = 1:size(idxm,2)
xrng = idxm(1,k) : idxm(2,k);
patch([x(xrng) flip(x(xrng))], [min(ylim)*ones(size(y(xrng))) flip(y(xrng))], 'r', 'FaceAlpha',0.5)
end
hold off
grid
.
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
