How to plot this?

조회 수: 7 (최근 30일)
BN
BN 2021년 10월 9일
댓글: BN 2021년 10월 9일
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
BN
BN 2021년 10월 9일
편집: BN 2021년 10월 9일
I tried to do it using this
mydata = table2array(mydata);
N = histcounts2(mydata(:,1),mydata(:, 2) ,'Normalization','cdf');
contour(N);
colorbar
but the range of x and y are not between 0 and 1.

댓글을 달려면 로그인하십시오.

채택된 답변

Dave B
Dave B 2021년 10월 9일
편집: Dave B 2021년 10월 9일
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)
load('mydata.mat')
mydata = table2array(cp);
[N,x,y] = histcounts2(mydata(:,1), mydata(:,2), 25, 'Normalization','cdf');
x=x(1:end-1)+diff(x)/2;
y=y(1:end-1)+diff(y)/2;
contour(x,y,N,'ShowText','on','LineWidth',3);
colorbar
colormap turbo
  댓글 수: 1
BN
BN 2021년 10월 9일
Thank you so much, that's exactly what I needed. Really appreciate you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by