Cumulative Contribution Contour Plot
Show older comments
I have a 2D weighting function of a certain area that gives 1 when summed over all columns and rows. I want to make a contour plot where the iso-lines represent the percentage cumulative contribution to the total. I have seen several questions on the web that refer to this exercise but found no answer. Can anyone help?
..
Below an example that illustrates what contour.m gives (which is not what I want):
% Construct Example Weighting Function
x1 = -3:.02:3; x2 = -3:.02:3;
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],[0 0],[.25 .3; .3 1]);
F = reshape(F,length(x2),length(x1));
F = F./sum(sum(F));
..
% Make Contour Plot
[C,h] = contour(x1,x2,F,10);
set(gca,'xlim',[-1.5,1.5],'ylim',[-2.5,2.5]);
clabel(C,h,'labelspacing',500)
..
--> Rather then these standard contour lines I want the first iso-line to represent the first 10% contribution to the total, the next contour line the 20% contribution to the total etc.
Accepted Answer
More Answers (3)
Andrew Newell
on 26 Jan 2011
You seem to be trying to plot the multivariate normal cumulative distribution function. For that, just change mvnpdf to mvncdf. You don't need the normalization step. Try this:
[X1,X2] = meshgrid(x1,x2);
F = mvncdf([X1(:) X2(:)],[0 0],[.25 .3; .3 1]);
[C,h] = contour(x1,x2,F,10);
set(gca,'xlim',[-1.5,1.5],'ylim',[-2.5,2.5]);
clabel(C,h,'labelspacing',500)
1 Comment
Oscar Hartogensis
on 26 Jan 2011
Andrew Newell
on 27 Jan 2011
0 votes
Oscar, the real issue here is how to define the cdf for your function. Once you can calculate it, you can do a contour plot of it as you would any other function. The question that only you can answer is, how do you want to define that cdf? For example, mvncdf(X) calculates the probability that a random vector will fall within some semi-infinite rectangle with upper limits defined by X (see the documentation). To get the equivalent for your pdf, you'd need to be able to integrate it analytically or numerically (possibly using the Symbolic Toolbox or one of the Matlab quadrature functions). But there are other ways you could define it - for example, distance from the point where the maximum value occurs. It all depends on how you want to use this function.
John Moseley
on 27 Jun 2013
0 votes
This is great Oscar. Thanks for posting.
John
Categories
Find more on Contour Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!