From 6b518fec228cfd4f3707741cc4508d6af07117bb Mon Sep 17 00:00:00 2001
From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu>
Date: Thu, 4 Feb 2021 16:22:25 +0100
Subject: [PATCH] Colors are now correctly assigned to respective classes.

---
 pysegcnn/core/graphics.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pysegcnn/core/graphics.py b/pysegcnn/core/graphics.py
index 0dc3d01..199946c 100644
--- a/pysegcnn/core/graphics.py
+++ b/pysegcnn/core/graphics.py
@@ -593,8 +593,9 @@ def plot_class_distribution(ds, figsize=(16, 9), alpha=0.5):
     npix_per_class = {k: '{:.2f}M'.format(v.shape[0] * 1e-6) for k, v in
                       cls_ds.items()}
 
-    # labels for the different classes
+    # labels and colors for the different classes
     labels = [ds.labels[cls_id]['label'] for cls_id in cls_ds.keys()]
+    colors = [ds.labels[cls_id]['color'] for cls_id in cls_ds.keys()]
 
     # number of spectral bands in the dataset
     nbands = len(ds.use_bands)
@@ -637,7 +638,7 @@ def plot_class_distribution(ds, figsize=(16, 9), alpha=0.5):
                     # patch artists
                     if isinstance(art, matplotlib.patches.Patch):
                         # set the colors of the patches
-                        art.set_facecolor(ds.labels[c]['color'])
+                        art.set_facecolor(colors[c])
                         art.set_alpha(alpha)
 
         # add name of the spectral band to the plot
-- 
GitLab