English 中文(简体)
Mathematica, PDF Curves and Shading
原标题:

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

最佳回答

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.

问题回答

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}]





相关问题
How to manage a pageview DB

I am interested in tracking my users pageviews on my site. Being that traffic is expanding very quickly, I am worried about robots, etc, and I also want to be able to use tracked data live to alter ...

Statistics Question

Suppose I conduct a survey of 10 people asking whether to rank a movie as 0 to 4 stars. Allowable answers are 0, 1, 2, 3, and 4. The mean is 2.0 stars. How do I calculate the certainty (or ...

Calculating variance with large numbers

I haven t really used variance calculation that much, and I don t know quite what to expect. Actually I m not too good with math at all. I have a an array of 1000000 random numeric values in the ...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Generating correlated numbers

Here is a fun one: I need to generate random x/y pairs that are correlated at a given value of Pearson product moment correlation coefficient, or Pearson r. You can imagine this as two arrays, array ...

Multivariate time series modelling in R

I want do fit some sort of multi-variate time series model using R. Here is a sample of my data: u cci bci cpi gdp dum1 dum2 dum3 dx 16.50 14.00 53.00 45.70 80....

热门标签