I have a question that is closely related to this one:
Normed histogram y-axis larger than 1
The solution of the above thread was to scale the dimensions of the axis properly. However, that solution was not working for my code:
import numpy as np
import matplotlib.pyplot as plt
from numpy import random
import seaborn as sns
np.random.seed(2023)
a = np.random.normal(0, 1, 100000)
sns.histplot(a, bins=np.arange(-5, 5, 0.01), stat='density', color = 'red')
plt.title("Standard Normal Distribution")
plt.xlabel('x')
plt.ylabel('F(x)', rotation=0)
plt.show()
The plot for the above code looks like this:
The above image is a standard normal distribution going from -5 to +5 on the x-axis with a step width of 0.01, just like defined by np.arange()
in the code.
Now I want to modify my code so that I'll get the exact same plot, everything in the same place just like above, but with the x-axis going from -500 to 500 instead of -5 to 5 with a step width of 1 instead of 0.01.
The above solution (Normed histogram y-axis larger than 1) suggests modifying the value a
, so that if the dimension in the x-axis gets multiplied by a factor of 100, I'd need to divide the y-axis by a factor of 100. However, modifying my code like this
import numpy as np
import matplotlib.pyplot as plt
from numpy import random
import seaborn as sns
np.random.seed(2023)
a = np.random.normal(0, 1, 100000)
b = a/ 100
sns.histplot(b, bins=np.arange(-500, 500, 1), stat='density', color = 'red')
plt.title("Standard Normal Distribution")
plt.xlabel('x')
plt.ylabel('F(x)', rotation=0)
plt.show()
results in a plot like this:
First of all is interesting because it raises another question: can something like this be considered a normally distributed function when it has just one possible probability area? So it's like a single square with a total area of 1?
Back to the original issue: How can I modify my code so that the plot will display x values between -500 and 500 with a step width of 1 on the x-axis and have y values in the center (x=0) that are about 0.004?
I think you wanted to use b = a * 100
Think of it this way: You generate a random list using normal distribution, with 100,000 elements, with a standard deviation of 1. If you divide that by 100, you will have a standard deviation of about 0.01. But with a step of 1, the chance of any numbers falling outside this one bar is effectively 0. Therefore, you have two options: