Clear Filters
Clear Filters

How to plot this?

2 views (last 30 days)
BN on 9 Oct 2021
Commented: BN on 9 Oct 2021
Dear all,
I have a table containing the cumulative distribution of 3 variables (x, y, and m). Now I want to plot contours of "m" for different "x "and "y" values. Just like this plot below:
If this is important m is the joint cumulative probability of x and y.
I attached my dataset, any advice is appreciated.
best regards.
  1 Comment
BN on 9 Oct 2021
Edited: BN on 9 Oct 2021
I tried to do it using this
mydata = table2array(mydata);
N = histcounts2(mydata(:,1),mydata(:, 2) ,'Normalization','cdf');
but the range of x and y are not between 0 and 1.

Sign in to comment.

Accepted Answer

Dave B
Dave B on 9 Oct 2021
Edited: Dave B on 9 Oct 2021
You can get an the x and y values for the edges from histcounts2, but that gives you one extra value (you want to tell contour the values at the centers of each bin not at the edges). The centers of the bins can be thought of as the first edge plus one half of the difference between the edges:
(I adjusted the number of bins, the linewidth, and the colormap, and I added labels to make it a little more similar to your example)
mydata = table2array(cp);
[N,x,y] = histcounts2(mydata(:,1), mydata(:,2), 25, 'Normalization','cdf');
colormap turbo
  1 Comment
BN on 9 Oct 2021
Thank you so much, that's exactly what I needed. Really appreciate you.

Sign in to comment.

More Answers (0)


Find more on Contour Plots in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!