I am reproducing a chart in a paper using the LOGNORM.DIST in Microsoft Excel 2013 and would like to get the same chart in Python. I am getting the correct answer in excel, but not in python.
In excel the I have,
mean of ln(KE) 4.630495093
std dev of ln(KE) 0.560774853
I then plot x (KE) from 10 to 1000 and using the Excel LOGNORM.DIST and calculate the probability of the event. I'm getting the exact answers from the paper so I'm confident in the calculation. The plot is below:
MS Excel 2013 Plot of LOGNORM.DIST
In python I'm using Python 3.4 and Scipy 0.16.0 and my code is as follows:
%matplotlib inline
from scipy.stats import lognorm
import numpy as np
import matplotlib.pyplot as plt
shape = 0.560774853 #standard deviation
scale = 4.630495093 #mean
loc = 0
dist=lognorm(shape, loc, scale)
x=np.linspace(10,1000,200)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_xscale('log')
ax.set_xlim([10., 1000.])
ax.set_ylim([0., 1.])
ax.plot(x,dist.cdf(x)), dist.cdf(103)
and the plot is,
I have messed around a lot with the loc parameter, but nothing works. The last line in the python code
dist.cdf(103)
should give me a 50% probability, but obviously I'm doing something wrong.
The
scale
parameter of the scipylognorm
distribution isexp(mean)
, wheremean
is the mean of the underlying normal distribution. So you should write:Here's a script that generates a plot like the Excel plot: