I am trying to draw the lognormal distribution for my data. using the following code :

mu, sigma = 136519., 50405. # mean and standard deviation

hs = np.random.lognormal(mu, sigma, 1000) #mean, s dev , Size

count, bins, ignored = plt.hist(hs, 100, normed=True) 

x = np.linspace(min(bins), max(bins), 10000)

pdf = (math.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)))

plt.plot(x, pdf, linewidth=2, color='r')

As you can see, my maean and sigma are big values, it creates the problem that hs goes to infinity that gives error .

while if I put something like mu =3 and sigma =1, it works, any suggestions for big numbers?


1 Answer 1


Simply generate normal variables $x_i\sim N(136519, 50405^2)$. Numpy should be able to handle this.

Then take exponentials: $e^{x_i}$. These are on the order of $e^{150,000}$. Numpy will likely not be able to handle this. If you really need numbers on this scale, look into dedicated libraries for working with big floats.

The lognormal distribution with log-mean $\mu$ and log-SD $\sigma$ has an expected value $e^{\mu+\frac{\sigma^2}{2}}$. For the values you have, this is about as close to infinity as you are likely to get, and actual realizations will of course be much larger.

  • $\begingroup$ Thank you so much! Unfortunately I'm new and can't give you positive vote $\endgroup$ Jul 31, 2018 at 10:22
  • $\begingroup$ Dear Stephan, I am actually trying to replicate this graph in Python, that can be producced ,maybe without problems, in MINITAB, so at this point, I have a bit of doubt, whether my work in python would get to the point to give the same results, because most of the times I will be working with big numbers $\endgroup$ Jul 31, 2018 at 11:57
  • $\begingroup$ Unfortunately, I'm not an expert in Python. If you are interested in plotting large numbers in Python, that would be off-topic here. These links may be helpful. $\endgroup$ Jul 31, 2018 at 12:00
  • $\begingroup$ You are right Stephan, I have been asking my statistics questions on Stackoverflow, though, regarding the fact that this is a mixed topic, there are few people that would be interested to answer my questions there , still I apperciate your answer $\endgroup$ Jul 31, 2018 at 12:03
  • $\begingroup$ Creating a given type of plot with large numbers should be perfectly on-topic at SO. It doesn't matter whether these numbers come from a statistical model. Just make sure you include a Minimum Working Example in your question. $\endgroup$ Jul 31, 2018 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.