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

3 views (last 30 days)
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.

Accepted Answer

the cyclist
the cyclist on 7 Mar 2023
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.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!