Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a joint density and distribution function that I want to plot in a meaningful way, (i.e., want to be able to see how the functions behaves as changes in x and y happen simultaneously. If possible, I would like for the x axis to stay horizontal (left to right), and the y axis going into the screen. No particular choice is in mind at the moment such as (Plot3D, ContourPlot3D, or DiscretePlot3D). More than one way of plotting is encouraged just to see all useful possibilities of grasping useful information on how the functions behave. Maybe even an example including Manipulate would be very helpful as well. The functions are here below:

 (pdf)...    f[x_, y_] := x^2 y E^(-x (y + 1)) UnitStep[x] UnitStep[y]

 (cdf)...    F[x_, y_] := (1 - E^-x + ((y x + 1) E^(-x (y + 1)))/(y + 1) +
             (y E^(-x (y + 1)) - 2 y - 1)/(y + 1)^2) UnitStep[x] UnitStep[y] 
share|improve this question

3 Answers 3

up vote 8 down vote accepted

I'm not sure if this is the best option, but in terms of graphics it would be interesting to plot and compare both continuous and discrete PDF's and CDF's, as well as contour plots.

Let me show what I usually do:

randomWalk[x_] := RandomVariate[NormalDistribution[0, 1], x]
index = Table[randomWalk[10000], {2}];
asset[i_] := index[[i]];
pair1 = Transpose[{asset[1], asset[2]}];

Now the discrete bivariate histogram:

G1 = Histogram3D[pair1, {0.25}, "PDF", ColorFunction -> "Rainbow"]

enter image description here

Now the continuous bivariate plot:

G2 = Plot3D[Evaluate@PDF[BinormalDistribution[0/1],{x, y}],{x,-3,3},{y,-3,3},ColorFunction->"Rainbow"]

enter image description here

The countour plot:

G3 = ContourPlot[PDF[BinormalDistribution[0/1],{x,y}],{x,-3,3},{y,-3,3},ColorFunction->"Rainbow"]

enter image description here

Plotting the CDF's. The discrete one:

G4 = Histogram3D[pair1, {0.25}, "CDF", ColorFunction -> "Rainbow"]

enter image description here

The continuous one:

G5 = Plot3D[CDF[BinormalDistribution[1/2],{x, y}],{x,-4,4},{y,-4, 4},ColorFunction->"Rainbow"]

enter image description here

And the CDF's contour plot:

G6 = ContourPlot[CDF[BinormalDistribution[1/2],{x,y}],{x,-4,4},{y,-4,4},ColorFunction->"Rainbow"]

enter image description here

P.S.: you can even mix the plots, showing them at the same time for comparison. You can try, for instance

Show[G1, G2]

enter image description here

Show[G4, G5]

enter image description here

UPDATE

Using your functions to plot the PDF, CDF and contour plots. Consider:

pdf[x_, y_] := x^2 y E^(-x (y + 1)) UnitStep[x] UnitStep[y];    
cdf[x_, y_] := (1 - E^-x + ((y x + 1) E^(-x (y + 1)))/(y + 1) + (y E^(-x (y + 1)) - 2 y - 1)/(y + 1)^2) UnitStep[x] UnitStep[y];

Now the plots:

Plot3D[Evaluate@pdf[x, y], {x, 0, 4}, {y, 0, 6}, ColorFunction -> "Rainbow", PlotRange -> All, Mesh -> Full, Exclusions -> None]

enter image description here

The PDF's contour plot:

ContourPlot[pdf[x, y], {x, 0, 4}, {y, 0, 6}, ColorFunction -> "Rainbow"]

enter image description here

The CDF:

Plot3D[Evaluate@cdf[x, y], {x, 0, 7}, {y, 0, 15},ColorFunction -> "Rainbow", PlotRange -> All, Mesh -> Full, Exclusions -> None]

enter image description here

And, finally, the CDF's contour plot:

ContourPlot[cdf[x, y], {x, 0, 7}, {y, 0, 15}, ColorFunction -> "Rainbow"]

enter image description here

I hope this is useful.

share|improve this answer
1  
Marvelous.. Exactly what I was in need for and also can see clearly how they behave. Now these examples are just generic (correct?) just to be clear. So I could just replace this with my very own results for the pdf and cdf? –  night owl Mar 9 '13 at 12:18
    
That's it! Just put your own data and voilá! –  Rod Mar 9 '13 at 12:20
    
You can substitute asset[1] and asset[2] with your own data. This should work... –  Rod Mar 9 '13 at 13:24
    
Not sure, I did the following: randomWalk[x_] := RandomVariate[NormalDistribution[0, 1], x] index = Table[randomWalk[10000], {2}]; asset[i_] := index[[i]]; pair1 = Transpose[{f[x,y], F[x,y]}]; It stated the transpose of f,F are not list of data sets. –  night owl Mar 9 '13 at 13:46
1  
Yes that's right. But I'll just stick to the continuous plots, the histogram just looked neat. :) –  night owl Mar 11 '13 at 4:01

Perhaps the simplest thing to do is to plot them using Plot3D

 Plot3D[f[x, y], {x, -1, 3}, {y, -1, 3}, PlotRange -> All]
 Plot3D[F[x, y], {x, -1, 3}, {y, -1, 3}, PlotRange -> All]

Once plotted, you can grab them with the mouse and rotate to get the best viewing angle. Or make it interactive to change between plotting styles

 Manipulate[GraphicsRow[{
    plot[f[x, y], {x, -1, 3}, {y, -1, 3}, PlotRange -> All],
    plot[F[x, y], {x, -1, 3}, {y, -1, 3}, PlotRange -> All]}, 
 ImageSize -> 600], {plot, {Plot3D, ContourPlot, DensityPlot}}]

different plotting commands

share|improve this answer

something quick to get you started.

DynamicModule[{xlim = 3, ylim = 3, xlimControl, ylimControl},

 xlimControl = 
  Row[{Text@"x limit", Spacer[5], 
    Manipulator[Dynamic[xlim, {xlim = #} &], {0.01, 5, 0.01}, 
     ImageSize -> Tiny, ContinuousAction -> True], Spacer[5], 
    Dynamic[AccountingForm[xlim, {3, 2}, NumberSigns -> {"", ""}, 
      NumberPadding -> {"0", "0"}]]}];

 ylimControl = 
  Row[{Text@"y limit", Spacer[5], 
    Manipulator[Dynamic[ylim, {ylim = #} &], {0.01, 5, 0.01}, 
     ImageSize -> Tiny, ContinuousAction -> True], Spacer[5], 
    Dynamic[AccountingForm[ylim, {3, 2}, NumberSigns -> {"", ""}, 
      NumberPadding -> {"0", "0"}]]}];

 Labeled[Grid[{

    {xlimControl},
    {ylimControl},

    {Dynamic[Grid[{{
         Plot3D[cdf[x, y], {x, -xlim, xlim}, {y, -ylim, ylim}, 
          AxesLabel -> {x, y, "cdf"}, Evaluate@commonPlotOptions, 
          PlotLabel -> "CDF"],
         Plot3D[pdf[x, y], {x, -xlim, xlim}, {y, -ylim, ylim}, 
          AxesLabel -> {x, y, "pdf"}, Evaluate@commonPlotOptions, 
          PlotLabel -> "PDF"]
         }}
       ]
      ]}
    }, Frame -> All, FrameStyle -> LightGray], "version 3/9/13"],

 Initialization :>
  {
   commonPlotOptions = {PlotRange -> All, ImagePadding -> 20, 
     PerformanceGoal -> Automatic, ImageSize -> 300, Mesh -> Full, 
     Exclusions -> None};
   pdf[x_, y_] := x^2 y E^(-x (y + 1)) UnitStep[x] UnitStep[y];

   cdf[x_, 
     y_] := (1 - 
       E^-x + ((y x + 1) E^(-x (y + 1)))/(y + 
          1) + (y E^(-x (y + 1)) - 2 y - 1)/(y + 1)^2) UnitStep[
      x] UnitStep[y];
   }
 ]

Mathematica graphics

share|improve this answer
    
+1.. Nice. Thanks for this. :) –  night owl Mar 9 '13 at 11:50
    
Would it be much to create these to DiscretePlot3D graphs. I've tried, but I think there are some conflicting options in discretized rendering of graphics. –  night owl Mar 9 '13 at 12:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.