Fill area between plot and the 0-line?

240 visualizaciones (últimos 30 días)
Julozert
Julozert el 31 de Mayo de 2020
Comentada: Harshit el 31 de Oct. de 2022
Hi,
I want to plot some data to show a difference to a reference value and i want that the curve above zero gets filled red and the area of the plot below zero gets filled with blue.
How do i do that?

Respuesta aceptada

Akira Agata
Akira Agata el 1 de Jun. de 2020
How about using area function?
The following is an example:
% Sample data
x = linspace(0,4*pi,1000);
y = sin(x);
% Extract positive and negative part
yp = (y + abs(y))/2;
yn = (y - abs(y))/2;
% Plot the data using area function
figure
area(x,yp,'FaceColor','r')
hold on
area(x,yn,'FaceColor','b')
  2 comentarios
Julozert
Julozert el 1 de Jun. de 2020
thank you very much
Harshit
Harshit el 31 de Oct. de 2022
ni chal ra

Iniciar sesión para comentar.

Más respuestas (2)

the cyclist
the cyclist el 31 de Mayo de 2020
You can use either the fill or patch command. See the examples there for guidance.
  3 comentarios
the cyclist
the cyclist el 31 de Mayo de 2020
The way I would do it is to use your data points to define polygons that are above zero, and polygons that are below zero, and then use patch or fill, to fill them in.
Julozert
Julozert el 31 de Mayo de 2020
How can i use my data points to define polygons?

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 1 de Jun. de 2020

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by