Mathematica, PDF Curves and Shading

statistics, wolfram-mathematica

Solution

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 the `Filling` option to get the shading. Then you display them together using `Show`, like so:

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

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.

Problem

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

Original source