Plot colouring from a value?

5 visualizaciones (últimos 30 días)
Sergio Cañete
Sergio Cañete el 27 de Abr. de 2021
Comentada: DGM el 28 de Abr. de 2021
Hello,
I'm looking at how to colour a plot from a certain value on the vertical axis. I have been looking at the documentation but I can only find how to create area plots with colours, or how to change the plot lines.
Any ideas?
Thank you very much!
  1 comentario
Jonas
Jonas el 27 de Abr. de 2021
so you want points with a certain y value be of different color than other values? you could just seperate the points before plotting into values with specific y value and plot them one after the other?

Iniciar sesión para comentar.

Respuestas (1)

DGM
DGM el 27 de Abr. de 2021
If you're trying to set regions of the plot background, consider the example:
% example data
t = linspace(0,8.5*pi,100);
f = -t.^2.*sin(t) + t.^2;
h1 = plot(t,f); % plot first so that x,y limits are known if not explicitly set
xl = get(gca,'xlim');
yl = get(gca,'ylim');
hold on; grid on
% create colored regions
patch(xl([1 2 2 1]),kron([800 yl(2)],[1 1]),'black','edgealpha',0,'facecolor',[0.985 0.471 0.453],'facealpha',0.2);
patch(xl([1 2 2 1]),kron([500 800],[1 1]),'black','edgealpha',0,'facecolor',[0.94 0.969 0.425],'facealpha',0.2);
patch(xl([1 2 2 1]),kron([yl(1) 500],[1 1]),'black','edgealpha',0,'facecolor',[0.13 0.723 0.419],'facealpha',0.2);
% throw a label in a region like the example shows
text(2,1000,'Oh No!','fontsize',14,'fontweight','bold')
uistack(h1,'top') % move the plot back to the top
  2 comentarios
Sergio Cañete
Sergio Cañete el 28 de Abr. de 2021
Thank you very much!!
DGM
DGM el 28 de Abr. de 2021
If the answer satisfies your needs, please click 'accept' so your question gets categorized accordingly.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects 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!

Translated by