From 5d514893f6fd4994ec0488a9fc0b92230539218a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 8 Feb 2022 13:55:26 +0100 Subject: [PATCH 1/2] Fix `plot_labels()` colored histogram bug --- utils/plots.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/plots.py b/utils/plots.py index 8bb5e98ba2b4..d02e63c61fd2 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -340,7 +340,10 @@ def plot_labels(labels, names=(), save_dir=Path('')): matplotlib.use('svg') # faster ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True)[1].ravel() y = ax[0].hist(c, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8) - [y[2].patches[i].set_color([x / 255 for x in colors(i)]) for i in range(nc)] # update colors bug #3195 + try: + [y[2].patches[i].set_color([x / 255 for x in colors(i)]) for i in range(nc)] # update colors bug #3195 + except Exception: + pass ax[0].set_ylabel('instances') if 0 < len(names) < 30: ax[0].set_xticks(range(len(names))) From 0671981c427d0efe654e2c0b8da29489f7de5d46 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 8 Feb 2022 13:57:19 +0100 Subject: [PATCH 2/2] Cleanup --- utils/plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index d02e63c61fd2..d6b83eac3d89 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -340,8 +340,8 @@ def plot_labels(labels, names=(), save_dir=Path('')): matplotlib.use('svg') # faster ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True)[1].ravel() y = ax[0].hist(c, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8) - try: - [y[2].patches[i].set_color([x / 255 for x in colors(i)]) for i in range(nc)] # update colors bug #3195 + try: # color histogram bars by class + [y[2].patches[i].set_color([x / 255 for x in colors(i)]) for i in range(nc)] # known issue #3195 except Exception: pass ax[0].set_ylabel('instances')