Skip to content

Commit

Permalink
Color overlapping points by most frequent color.
Browse files Browse the repository at this point in the history
  • Loading branch information
thocevar committed Aug 1, 2018
1 parent 3130077 commit a634455
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

# compute overlaps of points for use in compute_colors and compute_sizes
self.overlaps = []
points = defaultdict(list)
self.coord_to_id = defaultdict(list)
for i, xy in enumerate(zip(self.x_data, self.y_data)):
points[xy].append(i)
self.overlaps = [len(points[xy]) for i, xy in enumerate(zip(self.x_data, self.y_data))]
self.coord_to_id[xy].append(i)
self.overlaps = [len(self.coord_to_id[xy])
for i, xy in enumerate(zip(self.x_data, self.y_data))]
self.overlap_factor = [1+log2(o) for o in self.overlaps]

color_data, brush_data = self.compute_colors()
Expand Down Expand Up @@ -959,24 +960,23 @@ def compute_colors(self, keep_colors=False):
c_data = c_data.astype(int)
colors = np.r_[palette.getRGB(np.arange(n_colors)),
[[128, 128, 128]]]
pens = np.array(
pen_colors_palette = np.array(
[_make_pen(QColor(*col).darker(self.DarkerValue), 1.5)
for col in colors])
self.pen_colors = pens[c_data]
self.pen_colors = pen_colors_palette[c_data]
alpha = self.alpha_value if subset is None else 255
self.brush_colors = np.array([
brush_colors_palette = np.array([
[QBrush(QColor(0, 0, 0, 0)),
QBrush(QColor(col[0], col[1], col[2], alpha))]
for col in colors])
self.brush_colors = self.brush_colors[c_data]
self.brush_colors = brush_colors_palette[c_data]

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

if subset is not None:
brush = np.where(
Expand Down

0 comments on commit a634455

Please sign in to comment.