2

我正在尝试拟合对数正态曲线,但不确定如何将 y(和 x 轴)更改为对数刻度?我尝试使用 logspace 而不是 linspace,但出现错误

 OverflowError: cannot convert float infinity to integer

我试过了:

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

但这似乎也不起作用。. . 我附上了我的图表来告诉你我的意思。我真的看不到 400 附近发生了什么,所以我想对 y 进行对数缩放(并且对 x 进行对数缩放以进行比较)

from collections import Counter
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from scipy.stats import lognorm
import numpy as np

data = list(pre_data)
params = (0.40951093774076597, 5.1802137214177684, 60.158303995566413)
shape, loc, scale = params[0], params[1], params[2]
print params
prob = 1-lognorm.cdf(388,shape,loc=params[1], scale=params[2])
print prob * 2994
count, bins, ignored = plt.hist(data,100,normed=True)

mu = np.mean(np.log(data))
sigma = np.std(np.log(data))
x = np.linspace(min(bins),max(bins),10000)
pdf = (np.exp(-(np.log(x)-mu)**2 / (2 * sigma**2)) / (x * sigma * np.sqrt(2*np.pi)))
plt.plot(x,pdf,color='r',linewidth= 2)

在此处输入图像描述

4

1 回答 1

0
plt.xscale('log')
plt.yscale('log')
于 2014-12-08T01:22:20.717 回答