def _column1(): if role == Qt.DecorationRole: continuous_palette = ContinuousPaletteGenerator(*var.colors) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8).reshape( (1, 256)).repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: return "{} - {}".format(self._encode_color(var.colors[0]), self._encode_color(var.colors[1])) if role == ColorRole: return var.colors
def set_marker_color(self, attr, update=True): try: self._color_attr = variable = self.data.domain[attr] if len(self.data) == 0: raise Exception except Exception: self._color_attr = None self._legend_colors = [] else: if variable.is_continuous: self._raw_color_values = values = self.data.get_column_view(variable)[0].astype(float) self._scaled_color_values = scale(values) self._colorgen = ContinuousPaletteGenerator(*variable.colors) min = np.nanmin(values) self._legend_colors = (['c', self._legend_values(variable, [min, np.nanmax(values)]), [color_to_hex(i) for i in variable.colors if i]] if not np.isnan(min) else []) elif variable.is_discrete: _values = np.asarray(self.data.domain[attr].values) __values = self.data.get_column_view(variable)[0].astype(np.uint16) self._raw_color_values = _values[__values] # The joke's on you self._scaled_color_values = __values self._colorgen = ColorPaletteGenerator(len(variable.colors), variable.colors) self._legend_colors = ['d', self._legend_values(variable, range(len(_values))), list(_values), [color_to_hex(self._colorgen.getRGB(i)) for i in range(len(_values))]] finally: if update: self.redraw_markers_overlay_image(new_image=True)
def _get_colors(self): """Compute colors for different kinds of histograms.""" if self.target_var and self.target_var.is_discrete: colors = [[QColor(*color) for color in self.target_var.colors]] * self.n_bins elif self.target_var and self.target_var.is_continuous: palette = ContinuousPaletteGenerator(*self.target_var.colors) bins = np.arange(self.n_bins)[:, np.newaxis] edges = self.edges if self.attribute.is_discrete else self.edges[ 1:-1] # Need to digitize on `right` here so the samples will be assigned # to the correct bin for coloring bin_indices = ut.digitize(self.x, bins=edges, right=True) mask = bin_indices == bins colors = [] for bin_idx in range(self.n_bins): biny = self.y[mask[bin_idx]] if np.isfinite(biny).any(): mean = ut.nanmean(biny) / ut.nanmax(self.y) else: mean = 0 # bin is empty, color does not matter colors.append([palette[mean]]) else: colors = [[QColor('#ccc')]] * self.n_bins return colors
def _column1(): if role == Qt.DecorationRole: continuous_palette = ContinuousPaletteGenerator(*var.colors) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8). \ reshape((1, 256)). \ repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: return "{} - {}".format(self._encode_color(var.colors[0]), self._encode_color(var.colors[1])) if role == ColorRole: return var.colors
def get_color(self): if self.attr_color is None: return None colors = self.attr_color.colors if self.attr_color.is_discrete: self.discrete_palette = ColorPaletteGenerator( number_of_colors=len(colors), rgb_colors=colors) else: self.continuous_palette = ContinuousPaletteGenerator(*colors) return self.attr_color
def ctree(self, model=None): if model is not None: self.color_combo.clear() self.color_combo.addItem("Default") self.color_combo.addItem("Instances in node") self.color_combo.addItem("Impurity") self.color_combo.setCurrentIndex(self.color_index) self.scene.colorPalette = \ ContinuousPaletteGenerator(*model.domain.class_var.colors) super().ctree(model)
def _column1(): if role == Qt.DecorationRole: continuous_palette = \ ContinuousPaletteGenerator(*desc.get_colors()) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8). \ reshape((1, 256)). \ repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: colors = desc.get_colors() return f"{self._encode_color(colors[0])} " \ f"- {self._encode_color(colors[1])}" if role == ColorRole: return desc.get_colors() return None
def set_color_bins(self): if self.attr_color is None: self.thresholds = self.colors = None elif self.attr_color.is_discrete: self.thresholds = None self.colors = [QColor(*color) for color in self.attr_color.colors] else: col = self.data.get_column_view(self.attr_color)[0].astype(float) self.thresholds = decimal_binnings(col, min_bins=4)[0][1:-1] palette = ContinuousPaletteGenerator(*self.attr_color.colors) nbins = len(self.thresholds) + 1 self.colors = [palette[i / (nbins - 1)] for i in range(nbins)]
def get_color(self): if self.attr_color is None: return None colors = self.attr_color.colors if self.attr_color.is_discrete: self.discrete_palette = ColorPaletteGenerator( number_of_colors=min(len(colors), MAX), rgb_colors=colors if len(colors) <= MAX else DefaultRGBColors, ) else: self.continuous_palette = ContinuousPaletteGenerator(*colors) return self.attr_color
def get_color_index(self): color_index = -1 attr_color = self.attr_color if attr_color != "" and attr_color != "(Same color)": color_index = self.attribute_name_index[attr_color] color_var = self.data_domain[attr_color] colors = color_var.colors if color_var.is_discrete: self.discrete_palette = ColorPaletteGenerator( number_of_colors=len(colors), rgb_colors=colors) else: self.continuous_palette = ContinuousPaletteGenerator(*colors) return color_index
def __init__(self, scatter_widget, parent=None, _="None"): gui.OWComponent.__init__(self, scatter_widget) self.view_box = InteractiveViewBox(self) self.plot_widget = pg.PlotWidget(viewBox=self.view_box, parent=parent, background="w") self.plot_widget.getPlotItem().buttonsHidden = True self.plot_widget.setAntialiasing(True) self.plot_widget.sizeHint = lambda: QtCore.QSize(500, 500) self.replot = self.plot_widget.replot ScaleScatterPlotData.__init__(self) self.density_img = None self.scatterplot_item = None self.scatterplot_item_sel = None self.labels = [] self.master = scatter_widget self.shown_attribute_indices = [] self.shown_x = "" self.shown_y = "" self.pen_colors = self.brush_colors = None self.valid_data = None # np.ndarray self.selection = None # np.ndarray self.n_points = 0 self.gui = OWPlotGUI(self) self.continuous_palette = ContinuousPaletteGenerator( QColor(255, 255, 0), QColor(0, 0, 255), True) self.discrete_palette = ColorPaletteGenerator() self.selection_behavior = 0 self.legend = self.color_legend = None self.__legend_anchor = (1, 0), (1, 0) self.__color_legend_anchor = (1, 1), (1, 1) self.scale = None # DiscretizedScale self.subset_indices = None # self.setMouseTracking(True) # self.grabGesture(QPinchGesture) # self.grabGesture(QPanGesture) self.update_grid() self._tooltip_delegate = HelpEventDelegate(self.help_event) self.plot_widget.scene().installEventFilter(self._tooltip_delegate)
def set_labels(self, labels, variable=None, values=None): self.emit(SIGNAL("modelReset()")) self.labels = labels self.variable = variable self.values = values if isinstance(variable, ContinuousVariable): palette = ContinuousPaletteGenerator(*variable.colors) off, m = values.min(), values.max() fact = off != m and 1 / (m - off) self.label_colors = [palette[x] if not isnan(x) else Qt.lightGray for x in (values - off) * fact] else: self.label_colors = None self.emit(SIGNAL("modelReset()"))
def data(self, index, role=Qt.DisplayRole): row, col = index.row(), index.column() if col == 0: return ColorTableModel.data(self, index, role) if col > 1: return var = self.variables[row] if role == Qt.DecorationRole: continuous_palette = ContinuousPaletteGenerator(*var.colors) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8).\ reshape((1, 256)).\ repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: return "{} - {}".format(self._encode_color(var.colors[0]), self._encode_color(var.colors[1])) if role == ColorRole: return var.colors
def update_data(self, attributes, mid_labels=None): old_selection_conditions = self.selection_conditions self.clear() if self.data is None: return if len(attributes) < 2: return if self.show_statistics: self.alpha_value = TRANSPARENT self.alpha_value_2 = VISIBLE else: self.alpha_value = VISIBLE self.alpha_value_2 = TRANSPARENT self.attributes = attributes self.attribute_indices = [ self.domain.index(name) for name in self.attributes ] self.valid_data = self.get_valid_list(self.attribute_indices) self.visualized_mid_labels = mid_labels self.add_relevant_selections(old_selection_conditions) class_var = self.domain.class_var if not class_var: self.colors = None elif class_var.is_discrete: self.colors = class_var.colors elif class_var.is_continuous: self.colors = ContinuousPaletteGenerator(*class_var.colors) if self.group_lines: self.show_statistics = False self.draw_groups() else: self.show_statistics = False self.draw_curves() self.draw_distributions() self.draw_axes() self.draw_statistics() self.draw_mid_labels(mid_labels) self.draw_legend() self.replot()
def get_palette(self): """ Return a palette suitable for the current `attr_color` This method must be overridden if the widget offers coloring that is not based on attribute values. """ if self.attr_color is None: return None colors = self.attr_color.colors if self.attr_color.is_discrete: return ColorPaletteGenerator( number_of_colors=min(len(colors), MAX_CATEGORIES), rgb_colors=colors if len(colors) <= MAX_CATEGORIES else DefaultRGBColors) else: return ContinuousPaletteGenerator(*colors)
def ctree(self, model=None): """Input signal handler""" self.clear_scene() self.color_combo.clear() self.closeContext() self.model = model self.target_class_index = 0 if model is None: self.info.setText("No tree.") self.root_node = None self.dataset = None self.tree_adapter = None else: self.tree_adapter = self._get_tree_adapter(model) self.domain = model.domain self.dataset = model.instances if self.dataset is not None and self.dataset.domain != self.domain: self.clf_dataset = self.dataset.transform(model.domain) else: self.clf_dataset = self.dataset class_var = self.domain.class_var if class_var.is_discrete: self.scene.colors = [QColor(*col) for col in class_var.colors] self.color_label.setText("Target class: ") self.color_combo.addItem("None") self.color_combo.addItems(self.domain.class_vars[0].values) self.color_combo.setCurrentIndex(self.target_class_index) else: self.scene.colors = ContinuousPaletteGenerator( *model.domain.class_var.colors) self.color_label.setText("Color by: ") self.color_combo.addItems(self.COL_OPTIONS) self.color_combo.setCurrentIndex(self.regression_colors) self.openContext(self.domain.class_var) # self.root_node = self.walkcreate(model.root, None) self.root_node = self.walkcreate(self.tree_adapter.root) self.info.setText("{} nodes, {} leaves".format( self.tree_adapter.num_nodes, len(self.tree_adapter.leaves(self.tree_adapter.root)), )) self.setup_scene() self.Outputs.selected_data.send(None) self.Outputs.annotated_data.send( create_annotated_table(self.dataset, []))
def ctree(self, model=None): """Input signal handler""" self.clear_scene() self.color_combo.clear() self.closeContext() self.model = model if model is None: self.info.setText('No tree.') self.root_node = None self.dataset = None else: self.domain = model.domain self.dataset = model.instances if self.dataset is not None and self.dataset.domain != self.domain: self.clf_dataset = Table.from_table(model.domain, self.dataset) else: self.clf_dataset = self.dataset class_var = self.domain.class_var if class_var.is_discrete: self.scene.colors = [QColor(*col) for col in class_var.colors] self.color_label.setText("Target class: ") self.color_combo.addItem("None") self.color_combo.addItems(self.domain.class_vars[0].values) self.color_combo.setCurrentIndex(self.target_class_index) else: self.scene.colors = \ ContinuousPaletteGenerator(*model.domain.class_var.colors) self.color_label.setText("Color by: ") self.color_combo.addItems(self.COL_OPTIONS) self.color_combo.setCurrentIndex(self.regression_colors) self.openContext(self.domain.class_var) self.root_node = self.walkcreate(model.root, None) self.scene.addItem(self.root_node) self.info.setText('{} nodes, {} leaves'.format( model.node_count(), model.leaf_count())) self.setup_scene() self.send("Selected Data", None) self.send(ANNOTATED_DATA_SIGNAL_NAME, create_annotated_table(self.dataset, None))
def _get_colors(self): """Compute colors for different kinds of histograms.""" if self.target_var and self.target_var.is_discrete: colors = [[QColor(*color) for color in self.target_var.colors]] * self.n_bins elif self.target_var and self.target_var.is_continuous: palette = ContinuousPaletteGenerator(*self.target_var.colors) bins = np.arange(self.n_bins)[:, np.newaxis] edges = self.edges if self.attribute.is_discrete else self.edges[ 1:-1] bin_indices = ut.digitize(self.x, bins=edges) mask = bin_indices == bins colors = [] for bin_idx in range(self.n_bins): mean = ut.nanmean(self.y[mask[bin_idx]], axis=0) / self.y.max() colors.append([palette[mean]]) else: colors = [[QColor('#ccc')]] * self.n_bins return colors
def __init__(self, scatter_widget, parent=None, _="None", view_box=InteractiveViewBox): gui.OWComponent.__init__(self, scatter_widget) self.view_box = view_box(self) self.plot_widget = pg.PlotWidget(viewBox=self.view_box, parent=parent, background="w") self.plot_widget.getPlotItem().buttonsHidden = True self.plot_widget.setAntialiasing(True) self.plot_widget.sizeHint = lambda: QSize(500, 500) scene = self.plot_widget.scene() self._create_drag_tooltip(scene) self._data = None # Original Table as passed from widget to new_data before transformations self.replot = self.plot_widget.replot ScaleScatterPlotData.__init__(self) self.density_img = None self.scatterplot_item = None self.scatterplot_item_sel = None self.reg_line_item = None self.labels = [] self.master = scatter_widget self.master.Warning.add_message( "missing_coords", "Plot cannot be displayed because '{}' or '{}' is missing for " "all data points") self.master.Information.add_message( "missing_coords", "Points with missing '{}' or '{}' are not displayed") self.master.Information.add_message( "missing_size", "Points with undefined '{}' are shown in smaller size") self.master.Information.add_message( "missing_shape", "Points with undefined '{}' are shown as crossed circles") self.shown_attribute_indices = [] self.shown_x = self.shown_y = None self.pen_colors = self.brush_colors = None self.valid_data = None # np.ndarray self.selection = None # np.ndarray self.n_points = 0 self.gui = OWPlotGUI(self) self.continuous_palette = ContinuousPaletteGenerator( QColor(255, 255, 0), QColor(0, 0, 255), True) self.discrete_palette = ColorPaletteGenerator() self.selection_behavior = 0 self.legend = self.color_legend = None self.__legend_anchor = (1, 0), (1, 0) self.__color_legend_anchor = (1, 1), (1, 1) self.scale = None # DiscretizedScale self.subset_indices = None # self.setMouseTracking(True) # self.grabGesture(QPinchGesture) # self.grabGesture(QPanGesture) self.update_grid() self._tooltip_delegate = HelpEventDelegate(self.help_event) self.plot_widget.scene().installEventFilter(self._tooltip_delegate)
def _regression_get_color_palette(self): return ContinuousPaletteGenerator( *self.tree_adapter.domain.class_var.colors)
def get_palette(self): if self.is_continuous_color(): return ContinuousPaletteGenerator(Qt.white, Qt.black, False) else: return ColorPaletteGenerator(12)
def color_palette(self): return ContinuousPaletteGenerator(*self.tree.domain.class_var.colors)