Math, PDF Curves and Shading

I need to build a normal distribution and then shade some specific area. Now I am doing this by creating a distribution plot and overlaying it on RegionPlot. This is pretty confusing, and I'm sure there should be a more elegant way to do this. I googled, looked at the docs, found nothing. Help me SO!

I think Mathematica is considered programming ?: D

+3
source share
2 answers

The easiest approach I can come up with is to use two functions Plotin which you can select the range you want to shade, and the other the whole range, using the option Fillingto get the shading. Then you show them together using Show, for example:

distFn = PDF[NormalDistribution[], x];
Show[
   {Plot[distFn, {x, -5, 5}],
    Plot[distFn, {x, -1, 1}, Filling -> {1 -> {0, Automatic}}]},
   PlotRange -> All]

It is still a bit on the clumsy side, but it works, and it's easy enough to abstract into one function if you do.

+5
source

This can also be done with a single Plot operator.

mu = 4; sigma = 3;

distFn = PDF [NormalDistribution [mu, sigma], x];

Plot [Rate [distFn * {1, Boole [mu - sigma <x <mu + sigma]}], {x, mu - 3 sigma, mu + 3 sigma}, Fill → {2 → Axis}]

+2
source

Source: https://habr.com/ru/post/1723896/


All Articles