Color certain area of normal distribution

3 views (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 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 Comments
Hokkien
Hokkien on 5 Feb 2022
Thank you so much! I can understand it better right now! I will experiment with it.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 5 Feb 2022

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!