Skip to content

Instantly share code, notes, and snippets.

@niklasbuschmann
Last active November 8, 2020 15:21
Show Gist options
  • Save niklasbuschmann/8917d4f6a54a658a99f7d3efe1caa80e to your computer and use it in GitHub Desktop.
Save niklasbuschmann/8917d4f6a54a658a99f7d3efe1caa80e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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