Color certain area of normal distribution

3 Ansichten (letzte 30 Tage)
Hokkien
Hokkien am 5 Feb. 2022
Kommentiert: Star Strider am 5 Feb. 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!

Akzeptierte Antwort

Star Strider
Star Strider am 5 Feb. 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 Kommentare
Hokkien
Hokkien am 5 Feb. 2022
Thank you so much! I can understand it better right now! I will experiment with it.
Star Strider
Star Strider am 5 Feb. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 5 Feb. 2022

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by