Color certain area of normal distribution

조회 수: 3 (최근 30일)
Hokkien
Hokkien 2022년 2월 5일
댓글: Star Strider 2022년 2월 5일
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!

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 2월 5일

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by