Color certain area of normal distribution

3 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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