How do I plot two distributions on top of each other?

I fit this histogram with the distribution fitter app. This fit is called the "t position scale" in practice. On top of this histogram, I want to plot a distribution with a mean of 0 and a variance of 1. I would be very grateful if you could help me figure out how to do this.

Risposte (2)

You can write the plot command with the two variables that you have.
plot(data,density,data,distribution)
You can change the type of line adding markers.
plot(data,density,'b--',data,distribution,'k:')
If you don't use any markars, matlab chages only the color the of line.

1 Commento

actually, secondly, my chart view does not match the normal distribution. I need to make the Y axes at the same time.

Accedi per commentare.

To plot an additional distribution on the same axes, use the hold function. For the distribution itself, use the pdf function with a vector of ‘x’ values to create the data to plot. Several distributions could be characterised by those parameters, so choose the one you want.
.

6 Commenti

x = [-2:.1:2];
y = normpdf(x,0,1);
hold on
plot(x,y)
When I draw this distribution with hold on, this graph remains very small. How can I set the Y axes to be the same?
Multiply ‘y’ by an appropriate constant, similar to what I did in your previous Question.
@Star Strider I wrote such a code because I want the variance to be 0, but I get such an output, how can I fix it?
x = [-0.05:0.0001:0.05];
y = normpdf(x,0,1);
hold on
plot(x,200*y)
For a variance (or standard deviation) of 1, ‘x’ needs to be longer and still symmetrical:
x = [-0.05:0.0001:0.05] * 100;
y = normpdf(x,0,1);
figure
plot(x,200*y)
Otherwise, only the very top of the distributtion is visible. To get it to fit the displayed distribution, reduce σ
x = [-0.05:0.0001:0.05];
y = normpdf(x,0,0.0075);
figure
plot(x,200*y)
xlim([-1 1]*0.25)
text(-0.2,1E+4, '\it{N} (0, 0.0075)')
Experiment to get different results.
.
In fact, what I want to do here is to see how the fit I have drawn and the normal distribution with a mean of 0 and a variance of 1 will appear on top of each other. These two cannot be drawn together. I can't change the variance and the mean. Thank you for taking your time.
My pleasure!
To plot the requested distribution,. it will be necessary to use the first curve. The data and fitted distribution will then essentially be a thin vertical red line, however there is no way to avoid that if the objective is to plot both in a single axes object.
.

Accedi per commentare.

Categorie

Richiesto:

il 2 Ott 2021

Commentato:

il 4 Ott 2021

Community Treasure Hunt

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

Start Hunting!

Translated by