我有两个数组X和Y,它们的对数图给出了我想要拟合的对数正态分布。我的代码如下:
import yt
from yt.units import kpc
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import math
from scipy.optimize import curve_fit
import yt.visualization.eps_writer as eps
plt.switch_backend('agg')
filename="/lunarc/nobackup/users/samvad/FINAL-50-0.5/output/output_00029/info_00029.txt"
ds=yt.load(filename)
ds.define_unit("H", (1.674*10**(-24), "g"))
ad=ds.all_data()
dens=ad.cut_region(["obj['density'].in_units('H/cm**3') > 0"])
profile = yt.data_objects.profiles.create_profile(dens, [("gas","density")], [("gas","cell_mass")], weight_field=None, fractional=True)
X=profile.x.in_units("H/cm**3")
Y=profile[("gas","cell_mass")]
p=plt.loglog(X, profile[("gas","cell_mass")], 'b', label='139.05 Myr')
def fit_func(x, mu, sigma):
return (np.exp(-(np.log(x)-mu)**2 / (2 * sigma**2))) / (x * sigma * np.sqrt(2 * np.pi))
pfit, perr = curve_fit(fit_func, X, Y)
XX=np.logspace(-2, 6, num=100)
p=plt.semilogx(XX, pdf, color='b', linestyle='dashed')
但是,我的数据不适合我。 image here
Here is the link to my data(output_000029),请问有人可能出了什么问题。谢谢