Mar-02-2022, 08:37 AM
Hello, I just joined this community to learn Python. I'm not a programmer or developer. So, I'm learning Python from the beginning.
Today my question is how to draw the consistent Probability Density Function (PDF) plot regardless of sample size.
This is my code.
![[Image: 0yTHB.png]](https://i.stack.imgur.com/0yTHB.png)
and this is a graph. However, when I change the sample number from 1000 to 100 such as
![[Image: l8ocw.png]](https://i.stack.imgur.com/l8ocw.png)
This is because lack of sample size cannot represent full normal distribution. If we draw a normal distribution graph in Excel with limited sample size, we can find the same problem. Could you let me know how I can get a consistent normal distribution graph in Python? Regardless of sample size, I'd like to obtain the same shape of normal distribution graph in given mean and standard deviation.
Could you provide some codes for that?
Many thanks!!
Today my question is how to draw the consistent Probability Density Function (PDF) plot regardless of sample size.
This is my code.
# Library import numpy as np import pandas as pd import matplotlib.pyplot as plt import scipy.stats as stats # Data frame x = np.random.normal(45, 9, 1000) source = {"Genotype": ["CV1"]*1000, "AGW": x} df=pd.DataFrame(source) # Calculating PDF df_mean = np.mean(df["AGW"]) df_std = np.std(df["AGW"]) pdf = stats.norm.pdf(df["AGW"].sort_values(), df_mean, df_std) # Graph plt.plot(df["AGW"].sort_values(), pdf, color="black") plt.xlim([0,90]) plt.xlabel("Grain weight (mg)", size=12) plt.ylabel("Frequency", size=12) plt.grid(True, alpha=0.3, linestyle="--") plt.show()
![[Image: 0yTHB.png]](https://i.stack.imgur.com/0yTHB.png)
and this is a graph. However, when I change the sample number from 1000 to 100 such as
x = np.random.normal(45, 9, 100)
, the graph shape is changed.![[Image: l8ocw.png]](https://i.stack.imgur.com/l8ocw.png)
This is because lack of sample size cannot represent full normal distribution. If we draw a normal distribution graph in Excel with limited sample size, we can find the same problem. Could you let me know how I can get a consistent normal distribution graph in Python? Regardless of sample size, I'd like to obtain the same shape of normal distribution graph in given mean and standard deviation.
Could you provide some codes for that?
Many thanks!!