From 0b73ef4e2b26ea047f1ed6763f87f343a99890c3 Mon Sep 17 00:00:00 2001 From: janezd Date: Fri, 5 Nov 2021 12:40:09 +0100 Subject: [PATCH] Scatterplot: Use opacity for contrast --- .../widgets/visualize/owscatterplotgraph.py | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Orange/widgets/visualize/owscatterplotgraph.py b/Orange/widgets/visualize/owscatterplotgraph.py index a1f5d437d10..44cf6d4a070 100644 --- a/Orange/widgets/visualize/owscatterplotgraph.py +++ b/Orange/widgets/visualize/owscatterplotgraph.py @@ -1126,16 +1126,31 @@ def _get_discrete_colors(self, c_data, subset): c_data[np.isnan(c_data)] = len(self.palette) c_data = c_data.astype(int) colors = self.palette.qcolors_w_nan - pens = np.array( - [_make_pen(col.darker(self.DarkerValue), 1.5) for col in colors]) - pen = pens[c_data] - if self.alpha_value < 255: + if subset is None: + pens = np.array( + [_make_pen(col.darker(self.DarkerValue), 1.5) for col in colors]) + pen = pens[c_data] + if self.alpha_value < 255: + for col in colors: + col.setAlpha(self.alpha_value) + brushes = np.array([QBrush(col) for col in colors]) + brush = brushes[c_data] + else: + subset_colors = [QColor(col) for col in colors] for col in colors: - col.setAlpha(self.alpha_value) - brushes = np.array([QBrush(col) for col in colors]) - brush = brushes[c_data] - - if subset is not None: + col.setAlpha(int(224 - 0.7 * self.alpha_value)) + for col in subset_colors: + col.setAlpha(128 + 0.5 * self.alpha_value) + + pens, subset_pens = ( + np.array( + [_make_pen(col.darker(self.DarkerValue), 1.5) + for col in cols]) + for cols in (colors, subset_colors)) + pen = np.where(subset, subset_pens[c_data], pens[c_data]) + + brushes = np.array([QBrush(col) for col in subset_colors]) + brush = brushes[c_data] black = np.full(len(brush), QBrush(QColor(0, 0, 0, 0))) brush = np.where(subset, brush, black) return pen, brush