Last active
November 8, 2020 15:21
-
-
Save niklasbuschmann/8917d4f6a54a658a99f7d3efe1caa80e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.stats import norm | |
from scipy.optimize import curve_fit | |
def fn(x, a, mean, std): | |
return a * norm.pdf(x, mean, std) | |
x = np.linspace(50, 70, 11) | |
y = np.array([0.01, 0.12, 0.27, 0.63, 0.93, 0.97, 0.75, 0.46, 0.2, 0.03, 0.02]) | |
[a, mean, std], _ = curve_fit(fn, x, y, [1, 60, 1]) | |
x_gauss = np.linspace(50, 70, 100) | |
y_gauss = fn(x_gauss, a, mean, std) | |
plt.scatter(x, y) | |
plt.plot(x_gauss, y_gauss, label='x̅: {:.2f}, σ: {:.2f}'.format(mean, std)) | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment