Skip to content

Instantly share code, notes, and snippets.

@bkrmendy
Created June 1, 2022 14:51
Show Gist options
  • Save bkrmendy/7b3eadbd3402b93ae51725cb2fe5ded4 to your computer and use it in GitHub Desktop.
Save bkrmendy/7b3eadbd3402b93ae51725cb2fe5ded4 to your computer and use it in GitHub Desktop.
def plotDist(topplesize, xmin, xmax):
fit = powerlaw.Fit(
data = np.array(topplesize),
xmin = xmin,
xmax = xmax
)
x, y = fit.pdf(linear_bins=True)
ind = y>0
y = y[ind]
x = x[:-1]
x = x[ind]
tsize = np.array(topplesize)
fit = powerlaw.Fit(tsize[tsize>0], discrete=True, xmin=xmin, xmax=xmax)
alpha = fit.power_law.alpha
fig = plt.figure(figsize=(10,7))
ax1 = fig.add_subplot(1,1,1)
#ax1.scatter(x, y, color='r', s=1.2, label="PDF (scatter)")
powerlaw.plot_pdf(tsize[tsize>0], color='b', ax=ax1, linestyle='-', linewidth=2, label="PDF")
fit.power_law.plot_pdf(tsize[tsize>0], color='b', ax=ax1, linestyle='--', linewidth=1, label="Power-law fit")
plt.xlabel(r"Avalanche Size, $s$", fontsize=12)
plt.ylabel(r"$p(s)$", fontsize=12)
_ = plt.text(10e1,50e-4,r"$\alpha$="+str(round(alpha,1)), fontsize=13)
_ = plt.legend(frameon=False)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment