How to draw estimated kernel densities of two series in one figure?

조회 수: 2 (최근 30일)
I have two series of wage in 2007 and 2020. I would like to draw the estimated kernel densities of these series in on graph. How can I plot it? I have drawn estimated kernel densities, respectively. But I want to draw these in one figure.

채택된 답변

the cyclist
the cyclist 2023년 3월 7일
Here are two different methods
N = 50;
x1 = randn(N,1);
x2 = randn(N,1) + 1;
[f1,xi1] = ksdensity(x1);
[f2,xi2] = ksdensity(x2);
% Method 1
figure
plot(xi1,f1,"r-",xi2,f2,"g-")
% Method 2
figure
hold on
plot(xi1,f1,"r-")
plot(xi2,f2,"g-")
If I were doing this, I would probably do the KS density estimations at the same x points, rather than letting the default select the locations.

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by