Color certain area of normal distribution

1 visualización (últimos 30 días)
Hokkien
Hokkien el 5 de Feb. de 2022
Comentada: Star Strider el 5 de Feb. de 2022
Hi all,
I have two normal distributions as below:
y = normpdf(x,57565.67,1743.56);
y1 = normpdf(x,54908.02,1663.82);
I would like to set a left horizontal area color when x-axis is 54698, for y plot. At the same plot, I would like to set right horizonal area color when x-axis is 54698, for y1 plot. Is it possible that I can do this from property inspector?
The outcome will be something like this:
Thanks for the help!

Respuesta aceptada

Star Strider
Star Strider el 5 de Feb. de 2022
Try this —
x = linspace(4, 7, 250)*1E4;
y = @(x) normpdf(x,57565.67,1743.56);
y1 = @(x) normpdf(x,54908.02,1663.82);
xp = 54698;
xlx = x<=xp;
xhx = ~xlx;
figure
plot(x, y(x))
hold on
plot(x, y1(x))
patch([x(xlx) flip(x(xlx))], [y(x(xlx)) zeros(size(x(xlx)))], 'b', 'EdgeColor','none', 'FaceAlpha',0.75)
patch([x(xhx) flip(x(xhx))], [y1(x(xhx)) zeros(size(x(xhx)))], 'r', 'EdgeColor','none', 'FaceAlpha',0.95)
plot([1 1]*xp, y1([0 1]*xp), '-k', 'LineWidth',2.5)
hold off
text([5.4 5.6]*1E+4, [1 1]*1E-5, {'\alpha','\beta'}, 'Horiz','center', 'Vert','middle', 'FontWeight','bold', 'Color','g')
Experiment to get different results.
.
  2 comentarios
Hokkien
Hokkien el 5 de Feb. de 2022
Thank you so much! I can understand it better right now! I will experiment with it.
Star Strider
Star Strider el 5 de Feb. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 5 de Feb. de 2022

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by