Mathematica、PDF 曲线和阴影
我需要绘制正态分布,然后对它的某些特定区域进行着色。现在,我通过创建分布图并用 RegionPlot 覆盖它来完成此操作。这是相当复杂的,我确信一定有一种更优雅的方法来做到这一点。我用谷歌搜索,查看文档,一无所获。帮帮我吧!
我想 Mathematica 也算是编程吧? :D
I need to plot a normal distribution and then shade some specific region of it. Right now I'm doing this by creating a plot of the distribution and overlaying it with a RegionPlot. This is pretty convoluted and I'm certain there must be a more elegant way of doing it. I Googled, looked at the docs, found nothing. Help me SO!
I guess Mathematica counts as programming? :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的最简单的方法是使用两个
Plot
函数,其中一个绘制您想要着色的范围,另一个绘制整个范围,同时使用Filling
获得阴影的选项。然后使用Show
将它们显示在一起,如下所示:它仍然有点笨重,但它可以工作,并且如果您经常这样做,它应该很容易抽象为单个函数。
The easiest approach I can think of is to use two
Plot
functions, where one plots the range you want shaded, and the other one plots the entire range, while using theFilling
option to get the shading. Then you display them together usingShow
, like so:It's still a little on the clunky side, but it works, and it should be easy enough to abstract into a single function if you do it a lot.
也可以使用单个 Plot 语句来完成。
亩 = 4;西格玛=3;
distFn = PDF[
正态分布[mu, sigma],
x];
绘图[评估[distFn*
{1,布尔[mu - sigma < x < mu + 西格玛]}],
{x, mu - 3 sigma, mu + 3 sigma},
填充-> {2->轴}]
It can also be done with a single Plot statement.
mu = 4; sigma = 3;
distFn = PDF[
NormalDistribution[mu, sigma],
x];
Plot[Evaluate[distFn*
{1, Boole[mu - sigma < x < mu + sigma]}],
{x, mu - 3 sigma, mu + 3 sigma},
Filling -> {2 -> Axis}]