How to create curve in a plot scatter figure?

조회 수: 3 (최근 30일)
Dennis Huver
Dennis Huver 2017년 8월 30일
댓글: Dennis Huver 2017년 8월 31일
I am trying to create a curve in the plot, to show me density of the data(the dots). The curve needs to go up/down according to the scatter density, so that I can see where is most dense, where least and so on. I hope you get the picture. Thanks

채택된 답변

Steven Lord
Steven Lord 2017년 8월 30일
Use histcounts to count how much data is located in each bin along the X axis. Use the counts and edges in creating your plot. Alternately, use histogram with 'DisplayStyle', 'stairs'.
  댓글 수: 3
Dennis Huver
Dennis Huver 2017년 8월 31일
Hey Steven, histogram thing worked. But is there a way to use curve instead of stairs? Thanks!
Dennis Huver
Dennis Huver 2017년 8월 31일
found a way from another answer. N = histcounts(X, edges); centers = (edges(1:end-1) + edges(2:end))/2; plot(centers, N) works like a charm. if there is more elegant way, let me know. THanks again for the tip! :)

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

추가 답변 (1개)

José-Luis
José-Luis 2017년 8월 31일
편집: José-Luis 2017년 8월 31일
Convoluted way just to avoid repeating Steven's answer:
data = randn(5000,2); %First column xData, second column yData
[f,x] = ecdf(data(:,2));
[n,c] = ecdfhist(f,x,200);
x_val = linspace(min(data(:,1)),max(data(:,1)),200);
plot(data(:,1),data(:,2),'k.','LineWidth', 2);
hold on;
plot(c,n.*3,'r--')

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by