Skip to content

Commit a634455

Browse files
committed
Color overlapping points by most frequent color.
1 parent 3130077 commit a634455

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Orange/widgets/visualize/owscatterplotgraph.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from AnyQt.QtCore import Qt, QObject, QEvent, QRectF, QPointF, QSize
1111
from AnyQt.QtGui import (
12-
QStaticText, QColor, QPen, QBrush, QPainterPath, QTransform, QPainter, QKeySequence, QConicalGradient)
12+
QStaticText, QColor, QPen, QBrush, QPainterPath, QTransform, QPainter, QKeySequence)
1313
from AnyQt.QtWidgets import QApplication, QToolTip, QPinchGesture, \
1414
QGraphicsTextItem, QGraphicsRectItem, QAction
1515

@@ -714,10 +714,11 @@ def update_data(self, attr_x, attr_y, reset_view=True):
714714

715715
# compute overlaps of points for use in compute_colors and compute_sizes
716716
self.overlaps = []
717-
points = defaultdict(list)
717+
self.coord_to_id = defaultdict(list)
718718
for i, xy in enumerate(zip(self.x_data, self.y_data)):
719-
points[xy].append(i)
720-
self.overlaps = [len(points[xy]) for i, xy in enumerate(zip(self.x_data, self.y_data))]
719+
self.coord_to_id[xy].append(i)
720+
self.overlaps = [len(self.coord_to_id[xy])
721+
for i, xy in enumerate(zip(self.x_data, self.y_data))]
721722
self.overlap_factor = [1+log2(o) for o in self.overlaps]
722723

723724
color_data, brush_data = self.compute_colors()
@@ -959,24 +960,23 @@ def compute_colors(self, keep_colors=False):
959960
c_data = c_data.astype(int)
960961
colors = np.r_[palette.getRGB(np.arange(n_colors)),
961962
[[128, 128, 128]]]
962-
pens = np.array(
963+
pen_colors_palette = np.array(
963964
[_make_pen(QColor(*col).darker(self.DarkerValue), 1.5)
964965
for col in colors])
965-
self.pen_colors = pens[c_data]
966+
self.pen_colors = pen_colors_palette[c_data]
966967
alpha = self.alpha_value if subset is None else 255
967-
self.brush_colors = np.array([
968+
brush_colors_palette = np.array([
968969
[QBrush(QColor(0, 0, 0, 0)),
969970
QBrush(QColor(col[0], col[1], col[2], alpha))]
970971
for col in colors])
971-
self.brush_colors = self.brush_colors[c_data]
972+
self.brush_colors = brush_colors_palette[c_data]
972973

973-
# gray out overlapping points
974+
# color overlapping points by most frequent color
974975
for i, xy in enumerate(zip(self.x_data, self.y_data)):
975976
if self.overlaps[i] > 1:
976-
self.brush_colors[i] = [
977-
QBrush(QColor(0, 0, 0, 0)),
978-
QBrush(QColor(128, 128, 128, alpha))]
979-
self.pen_colors[i] = _make_pen(QColor(128, 128, 128).darker(self.DarkerValue), 1.5)
977+
c = Counter(c_data[j] for j in self.coord_to_id[xy]).most_common(1)[0][0]
978+
self.brush_colors[i] = brush_colors_palette[c]
979+
self.pen_colors[i] = pen_colors_palette[c]
980980

981981
if subset is not None:
982982
brush = np.where(

0 commit comments

Comments
 (0)