|
13 | 13 |
|
14 | 14 | import random |
15 | 15 | import sys |
16 | | -import warnings |
17 | 16 | from collections import Counter |
18 | 17 |
|
19 | 18 | import matplotlib.pyplot as plt |
@@ -86,14 +85,20 @@ def ascii_histogram(seq) -> None: |
86 | 85 | print("bin_edges:", bin_edges) |
87 | 86 |
|
88 | 87 | bcounts = np.bincount(a) |
89 | | -hist, _ = np.histogram(a, range=(0, max(a)), bins=max(a) + 1) |
| 88 | +hist, _ = np.histogram(a, range=(0, np.max(a)), bins=np.max(a) + 1) |
90 | 89 | print(bcounts) |
91 | 90 | assert np.array_equal(hist, bcounts), "Bincounts unequal." |
92 | 91 |
|
93 | 92 | # Reproducing `collections.Counter` |
94 | 93 | print( |
95 | 94 | "Reproducing `collections.Counter`:", |
96 | | - dict(zip(np.unique(a), bcounts[bcounts.nonzero()], strict=False)), |
| 95 | + dict( |
| 96 | + zip( |
| 97 | + np.unique(a).tolist(), |
| 98 | + bcounts[bcounts.nonzero()].tolist(), |
| 99 | + strict=False, |
| 100 | + ) |
| 101 | + ), |
97 | 102 | ) |
98 | 103 |
|
99 | 104 |
|
@@ -191,17 +196,17 @@ def ascii_histogram(seq) -> None: |
191 | 196 | # --------------------------------------------------------------------- |
192 | 197 |
|
193 | 198 | sns.set_style("darkgrid") |
194 | | -# Suppress the kwarg warning related to normed/density from Matplotlib. |
195 | | -with warnings.catch_warnings(): |
196 | | - warnings.simplefilter("ignore", category=UserWarning) |
| 199 | +sns.histplot(d, kde=True) |
| 200 | +plt.title("Seaborn's histplot()") |
| 201 | +plt.show() |
197 | 202 |
|
198 | | - sns.distplot(d) |
199 | | - plt.title("Seaborn's distplot()") |
200 | | - plt.show() |
| 203 | +params = stats.laplace.fit(d) |
| 204 | +x_laplace = np.linspace(d.min(), d.max(), num=250) |
201 | 205 |
|
202 | | - sns.distplot(d, fit=stats.laplace, kde=False) |
203 | | - plt.title("Histogram with Fitted Laplace Distribution") |
204 | | - plt.show() |
| 206 | +ax = sns.histplot(d, stat="density") |
| 207 | +ax.plot(x_laplace, stats.laplace.pdf(x_laplace, *params)) |
| 208 | +plt.title("Histogram with Fitted Laplace Distribution") |
| 209 | +plt.show() |
205 | 210 |
|
206 | 211 |
|
207 | 212 | data = np.random.choice( |
|
0 commit comments