MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: RE: Does Mathematica do transparent colors?


In a message dated 2001/10/28 4:58:54 AM, tgarza01 at prodigy.net.mx writes:

>I see your point, and my first guess is that you are asking for something
>which, if not too difficult, it takes a lot of labor, and may not be 
worthwhile.
>A single graphics object has to be constructed out of two different ones,
>in order to attain that "translucency" you want. When you use Show[a1,a2]
>to display two plots, even with colors that look very transparent, a1 
overrides
>whatever happens to be beneath. But I wonder if the following appoach could
>be useful to you:
>
>In[1]:=
><<Graphics`Graphics`;
><<Statistics`ContinuousDistributions`;
><<Statistics`DiscreteDistributions`;
><<Graphics`FilledPlot`;
>In[3]:=
>bern=BinomialDistribution[10,0.5];
>norm=NormalDistribution[6,Sqrt[2.5]];
>In[5]:=
>bc=BarChart[Transpose[{Table[PDF[bern,j],{j,0,10}],Range[0,10]}],
>      BarStyle->GrayLevel[0.9],DisplayFunction->Identity];
>In[6]:=
>fp=FilledPlot[PDF[norm,x],{x,0,11},DisplayFunction->Identity];
>In[7]:=
>Show[fp,bc,DisplayFunction->$DisplayFunction];
>  
>This, I'm afraid, is as good as it gets, unless you want to do a good deal
>of tampering with the graphics objects.
>

Needs["Graphics`Graphics`"];
Needs["Statistics`ContinuousDistributions`"];
Needs["Statistics`DiscreteDistributions`"];
Needs["Graphics`FilledPlot`"];

bern=BinomialDistribution[10,1/2];
norm=NormalDistribution[6,Sqrt[5/2]];

The chart distorts the comparison of the distributions.  
They do not have the same mean.

Mean[#]& /@ {bern, norm}

{5, 6}

A more representative comparison of these distributions is

DisplayTogether[
    FilledPlot[PDF[norm,x],{x,0,11}], 
    BarChart[Table[PDF[bern,j],{j,10}],
      BarStyle->GrayLevel[0.9]]];

The normal distribution corresponding to the binomial is

norm = NormalDistribution[5, Sqrt[5/2]];

DisplayTogether[
    FilledPlot[PDF[norm,x],{x,0,11}], 
    BarChart[Table[PDF[bern,j],{j,10}],
      BarStyle->GrayLevel[0.9]]];

A more general approach uses GeneralizedBarChart

Clear[n,p];

#[BinomialDistribution[n, p]]& /@ 
  {Mean, StandardDeviation}

{n*p, Sqrt[n*(1 - p)*p]}

n = Random[Integer, {10, 20}];
p = Random[Real , {1/4, 1/2}];
m = n*p;
s = Sqrt[n*p*(1-p)];

norm = NormalDistribution[m, s];
bern = BinomialDistribution[n, p];

DisplayTogether[
    FilledPlot[PDF[norm,x],{x,m-3.5s,m+3.5s}], 
    GeneralizedBarChart[
      Table[{j, PDF[bern,j], 0.8},
        {j,Floor[m-4s], Ceiling[m+4s]}],
      BarStyle->GrayLevel[0.9]], 
    Frame -> True, Axes -> False, 
    PlotLabel -> StringForm["n = ``, p = ``; m = ``, s = ``", 
        n, NumberForm[p, {5,2}], NumberForm[m, {5,2}], 
        NumberForm[s, {5,2}]]];


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: Simplify with If and UnitStep
  • Next by Date: Re: Unwanted color in postscript output
  • Previous by thread: RE: Does Mathematica do transparent colors?
  • Next by thread: Re: Does Mathematica do transparent colors?