ovlay cdf plot on histogram

Hi there,
I'm trying to overlay a cdf plot over a histogram like in this picture
I'm using this code but the cdf plot is not showing up over the histogram.
hist(x)
hold on
cdfplot(x)
I would appreciate any help.
Thanks

 Respuesta aceptada

Tom Lane
Tom Lane el 5 de Oct. de 2012
Editada: Tom Lane el 6 de Oct. de 2012

1 voto

It's there but it's on the histogram scale and it is obscured by the bars. Try this instead to put the cdf on a separate y axis:
x = randn(30,1);
[y2,x2] = ecdf(x);
[y1,x1] = hist(x);
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')

1 comentario

Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco el 17 de Abr. de 2021
Dear Tom,
thank you for your explanation.
It helped me to produce the graph attached.
Best.
Best.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 5 de Oct. de 2012

Comentada:

el 17 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by