Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fitting Maxwell-Boltzman distribution in Python

Is it possible to make a fit to Maxwell-Boltzmann like data in matplotlib or similar module in python?

like image 454
Michal Avatar asked Aug 24 '26 09:08

Michal


1 Answers

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()

enter image description here

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)
like image 72
unutbu Avatar answered Aug 25 '26 21:08

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!