diff --git a/histograms/histograms.py b/histograms/histograms.py index 495879433e..6469fb19f9 100644 --- a/histograms/histograms.py +++ b/histograms/histograms.py @@ -13,7 +13,6 @@ import random import sys -import warnings from collections import Counter import matplotlib.pyplot as plt @@ -86,14 +85,20 @@ def ascii_histogram(seq) -> None: print("bin_edges:", bin_edges) bcounts = np.bincount(a) -hist, _ = np.histogram(a, range=(0, max(a)), bins=max(a) + 1) +hist, _ = np.histogram(a, range=(0, np.max(a)), bins=np.max(a) + 1) print(bcounts) assert np.array_equal(hist, bcounts), "Bincounts unequal." # Reproducing `collections.Counter` print( "Reproducing `collections.Counter`:", - dict(zip(np.unique(a), bcounts[bcounts.nonzero()], strict=False)), + dict( + zip( + np.unique(a).tolist(), + bcounts[bcounts.nonzero()].tolist(), + strict=False, + ) + ), ) @@ -191,17 +196,17 @@ def ascii_histogram(seq) -> None: # --------------------------------------------------------------------- sns.set_style("darkgrid") -# Suppress the kwarg warning related to normed/density from Matplotlib. -with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=UserWarning) +sns.histplot(d, kde=True) +plt.title("Seaborn's histplot()") +plt.show() - sns.distplot(d) - plt.title("Seaborn's distplot()") - plt.show() +params = stats.laplace.fit(d) +x_laplace = np.linspace(d.min(), d.max(), num=250) - sns.distplot(d, fit=stats.laplace, kde=False) - plt.title("Histogram with Fitted Laplace Distribution") - plt.show() +ax = sns.histplot(d, stat="density") +ax.plot(x_laplace, stats.laplace.pdf(x_laplace, *params)) +plt.title("Histogram with Fitted Laplace Distribution") +plt.show() data = np.random.choice( diff --git a/histograms/requirements.txt b/histograms/requirements.txt new file mode 100644 index 0000000000..154d0e228b --- /dev/null +++ b/histograms/requirements.txt @@ -0,0 +1,5 @@ +matplotlib==3.11.2 +numpy==2.5.3 +pandas==3.0.6 +scipy==1.18.1 +seaborn==0.13.2