Fitting Maxwell-Boltzman distribution in Python
10,598
scipy.stats has support for the maxwell distribution.
import scipy.stats as stats
import matplotlib.pyplot as plt
import numpy as np
maxwell = stats.maxwell
data = maxwell.rvs(loc=0, scale=5, size=10000)
params = maxwell.fit(data, floc=0)
print(params)
# (0, 4.9808603062591041)
plt.hist(data, bins=20, normed=True)
x = np.linspace(0, 25, 100)
plt.plot(x, maxwell.pdf(x, *params), lw=3)
plt.show()
The first parameter is the location or shift away from zero.
The second parameter is the scaling parameter, denoted by a
on the wikipedia page.
To generate random variates (random data) with this distribution, use its rvs
method:
newdata = maxwell.rvs(*params, size=100)
Author by
Michal
Updated on June 05, 2022Comments
-
Michal almost 2 years
Is it possible to make a fit to Maxwell-Boltzmann like data in matplotlib or similar module in python?