Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CCDF plots #281

Open
charlesmartin14 opened this issue Sep 1, 2023 · 2 comments
Open

Add support for CCDF plots #281

charlesmartin14 opened this issue Sep 1, 2023 · 2 comments

Comments

@charlesmartin14
Copy link
Member

charlesmartin14 commented Sep 1, 2023

The current PDF plots require on a histogram and frequently we don't have enough data to have 100 bins and the plots can look distorted

it is suggested to add an option to have powerlaw PDF and CCDF plots directly
Here's an example of a CCDF

import numpy as np
import matplotlib.pyplot as plt
import powerlaw

# Generate some heavy-tailed data, e.g., from a Pareto distribution
data = esd1#np.random.pareto(a=2, size=1000) + 1

# Fit the data to a power-law
fit = powerlaw.Fit(data, discrete=False)

# Plot
plt.figure(figsize=(10, 7))

# Empirical Data CCDF
powerlaw.plot_ccdf(data, color='b', linestyle='-', label="Empirical Data")

# Power-law Fit CCDF
fit.power_law.plot_ccdf(ax=plt.gca(), color='r', linestyle='--', label=f"Powerlaw Fit (alpha={fit.alpha:.2f})")

plt.xlabel('Value')
plt.ylabel('CCDF')
plt.title('CCDF of Empirical Data and Powerlaw Fit')
plt.legend()
plt.grid(True, which="both", ls="--", c='0.7')
plt.show()

@charlesmartin14
Copy link
Member Author

image

@charlesmartin14
Copy link
Member Author

charlesmartin14 commented Sep 1, 2023

We could also add back the PDF from powerlaw
BUT we need to run Powerlaw to do these--


import numpy as np
import matplotlib.pyplot as plt
import powerlaw

# Generate some heavy-tailed data, e.g., from a Pareto distribution
data = esd1#np.random.pareto(a=2, size=1000) + 1

# Fit the data to a power-law
fit = powerlaw.Fit(data, discrete=False)

# Plot
fig, ax1 = plt.subplots(figsize=(10, 7))

# PDF (on primary y-axis)
powerlaw.plot_pdf(data, ax=ax1, color='b', linestyle='-', label="Empirical Data PDF")
fit.power_law.plot_pdf(ax=ax1, color='r', linestyle='--', label=f"Powerlaw Fit PDF (alpha={fit.alpha:.2f})")

ax1.set_xlabel('Value')
ax1.set_ylabel('PDF')
ax1.tick_params('y', colors='b')
ax1.legend(loc='upper left')
ax1.grid(True, which="both", ls="--", c='0.7')

# CCDF (on secondary y-axis)
ax2 = ax1.twinx()
powerlaw.plot_ccdf(data, ax=ax2, color='green', linestyle=':', label="Empirical Data CCDF", marker='o', markersize=3)
fit.power_law.plot_ccdf(ax=ax2, color='orange', linestyle='-.', label=f"Powerlaw Fit CCDF (alpha={fit.alpha:.2f})")

ax2.set_ylabel('CCDF')
ax2.tick_params('y', colors='r')
ax2.legend(loc='upper right')

plt.title('PDF and CCDF of Empirical Data and Powerlaw Fit')
plt.show()

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant