How to add a patch to a plot of data?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Star Strider
el 26 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
