|
9 | 9 |
|
10 | 10 | from AnyQt.QtCore import Qt, QObject, QEvent, QRectF, QPointF, QSize |
11 | 11 | from AnyQt.QtGui import ( |
12 | | - QStaticText, QColor, QPen, QBrush, QPainterPath, QTransform, QPainter, QKeySequence, QConicalGradient) |
| 12 | + QStaticText, QColor, QPen, QBrush, QPainterPath, QTransform, QPainter, QKeySequence) |
13 | 13 | from AnyQt.QtWidgets import QApplication, QToolTip, QPinchGesture, \ |
14 | 14 | QGraphicsTextItem, QGraphicsRectItem, QAction |
15 | 15 |
|
@@ -714,10 +714,11 @@ def update_data(self, attr_x, attr_y, reset_view=True): |
714 | 714 |
|
715 | 715 | # compute overlaps of points for use in compute_colors and compute_sizes |
716 | 716 | self.overlaps = [] |
717 | | - points = defaultdict(list) |
| 717 | + self.coord_to_id = defaultdict(list) |
718 | 718 | 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))] |
721 | 722 | self.overlap_factor = [1+log2(o) for o in self.overlaps] |
722 | 723 |
|
723 | 724 | color_data, brush_data = self.compute_colors() |
@@ -959,24 +960,23 @@ def compute_colors(self, keep_colors=False): |
959 | 960 | c_data = c_data.astype(int) |
960 | 961 | colors = np.r_[palette.getRGB(np.arange(n_colors)), |
961 | 962 | [[128, 128, 128]]] |
962 | | - pens = np.array( |
| 963 | + pen_colors_palette = np.array( |
963 | 964 | [_make_pen(QColor(*col).darker(self.DarkerValue), 1.5) |
964 | 965 | for col in colors]) |
965 | | - self.pen_colors = pens[c_data] |
| 966 | + self.pen_colors = pen_colors_palette[c_data] |
966 | 967 | alpha = self.alpha_value if subset is None else 255 |
967 | | - self.brush_colors = np.array([ |
| 968 | + brush_colors_palette = np.array([ |
968 | 969 | [QBrush(QColor(0, 0, 0, 0)), |
969 | 970 | QBrush(QColor(col[0], col[1], col[2], alpha))] |
970 | 971 | for col in colors]) |
971 | | - self.brush_colors = self.brush_colors[c_data] |
| 972 | + self.brush_colors = brush_colors_palette[c_data] |
972 | 973 |
|
973 | | - # gray out overlapping points |
| 974 | + # color overlapping points by most frequent color |
974 | 975 | for i, xy in enumerate(zip(self.x_data, self.y_data)): |
975 | 976 | 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] |
980 | 980 |
|
981 | 981 | if subset is not None: |
982 | 982 | brush = np.where( |
|
0 commit comments