在Python中记录比例mathplotlib?

时间:2014-12-08 00:30:24

标签: python graph matplotlib scale natural-logarithm

我试图拟合对数正态曲线,我不确定如何将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)

enter image description here

1 个答案:

答案 0 :(得分:0)

plt.xscale('log')
plt.yscale('log')