def draw_groups(self):
        if self.original_data is None:
            return

        phis, mus, sigmas = self.compute_groups()
        indices = [self.attribute_name_index[label] for label in self.visualizedAttributes]

        diff, mins = [], []
        for i in indices:
            if isinstance(self.data_domain[i], Continuous):
                diff.append(self.domain_data_stat[i].max - self.domain_data_stat[i].min or 1)
                mins.append(self.domain_data_stat[i].min)
            else:
                attribute_values = get_variable_values_sorted(self.data_domain[i])
                attr_len = len(attribute_values)
                diff.append(attr_len)
                mins.append(1/(2 * attr_len))

        for j, (phi, cluster_mus, cluster_sigma) in enumerate(zip(phis, mus, sigmas)):
            for i, (mu1, sigma1, mu2, sigma2), in enumerate(
                    zip(cluster_mus, cluster_sigma, cluster_mus[1:], cluster_sigma[1:])):
                nmu1 = (mu1 - mins[i]) / diff[i]
                nmu2 = (mu2 - mins[i + 1]) / diff[i + 1]
                nsigma1 = sqrt(sigma1) / diff[i]
                nsigma2 = sqrt(sigma2) / diff[i + 1]
                color = self.discPalette.getRGB(j)

                self.draw_group(i, nmu1, nmu2, nsigma1, nsigma2, phi, color)
        self.replot()
Example #2
0
    def _update_arrow_values(self, index):
        if not self.have_data:
            return

        if self.tooltipKind == 1:
            shown_attrs = [anchor[3] for anchor in self.anchor_data]
            self.show_tooltip(self.get_example_tooltip_text(self.raw_data[index], shown_attrs))
            return
        elif self.tooltipKind == 2:
            self.show_tooltip(self.get_example_tooltip_text(self.raw_data[index]))
            return

        if index == self._last_index:
            return
        self._last_index = index
        self._arrow_lines = []
        example = self.original_data.T[index]
        for x, y, z, attribute in self.anchor_data:
            value = example[self.attribute_name_index[attribute]]
            if value < 0:
                x = y = z = 0
            max_value = self.attr_values[attribute][1]
            factor = value / max_value
            if self.data_domain[attribute].varType == Discrete:
                value = get_variable_values_sorted(self.data_domain[attribute])[int(value)]
            if self.useDifferentColors and self.data_has_discrete_class:
                color = self.discrete_palette.getColor(example[self.data_class_index])
            else:
                color = QColor(0, 0, 0)
            self._arrow_lines.append([x, y, z, value, factor, color])
        self._mouseover_called = True
        self.update()
Example #3
0
    def update_properties(self):
        ## Mostly copied from OWScatterPlotGraph
        if not self.plot():
            return
            
        if not self.rect:
            x,y = self.axes()
            self.rect = self.plot().data_rect_for_axes(x,y)
        s = self.graph_transform().mapRect(self.rect).size().toSize()
        if not s.isValid():
            return
        rx = s.width()
        ry = s.height()
        
        rx -= rx % self.granularity
        ry -= ry % self.granularity
                
        p = self.graph_transform().map(QPointF(0, 0)) - self.graph_transform().map(self.rect.topLeft())
        p = p.toPoint()
        
        ox = p.x()
        oy = -p.y()
        
        if self.classifier.classVar.varType == orange.VarTypes.Continuous:
            imagebmp = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale)
            palette = [qRgb(255.*i/255., 255.*i/255., 255-(255.*i/255.)) for i in range(255)] + [qRgb(255, 255, 255)]
        else:
            imagebmp, nShades = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale, self.spacing)
            palette = []
            sortedClasses = get_variable_values_sorted(self.classifier.domain.classVar)
            for cls in self.classifier.classVar.values:
                color = self.plot().discPalette.getRGB(sortedClasses.index(cls))
                towhite = [255-c for c in color]
                for s in range(nShades):
                    si = 1-float(s)/nShades
                    palette.append(qRgb(*tuple([color[i]+towhite[i]*si for i in (0, 1, 2)])))
            palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))])

        self.potentialsImage = QImage(imagebmp, rx, ry, QImage.Format_Indexed8)
        self.potentialsImage.setColorTable(ColorPalette.signedPalette(palette) if qVersion() < "4.5" else palette)
        self.potentialsImage.setNumColors(256)
        self.pixmap_item.setPixmap(QPixmap.fromImage(self.potentialsImage))
        self.pixmap_item.setPos(self.graph_transform().map(self.rect.bottomLeft()))
Example #4
0
    def _update_arrow_values(self, index):
        if not self.have_data:
            return

        if self.tooltipKind == 1:
            shown_attrs = [anchor[3] for anchor in self.anchor_data]
            self.show_tooltip(
                self.get_example_tooltip_text(self.raw_data[index],
                                              shown_attrs))
            return
        elif self.tooltipKind == 2:
            self.show_tooltip(
                self.get_example_tooltip_text(self.raw_data[index]))
            return

        if index == self._last_index:
            return
        self._last_index = index
        self._arrow_lines = []
        example = self.original_data.T[index]
        for x, y, z, attribute in self.anchor_data:
            value = example[self.attribute_name_index[attribute]]
            if value < 0:
                x = y = z = 0
            max_value = self.attr_values[attribute][1]
            factor = value / max_value
            if self.data_domain[attribute].varType == Discrete:
                value = get_variable_values_sorted(
                    self.data_domain[attribute])[int(value)]
            if self.useDifferentColors and self.data_has_discrete_class:
                color = self.discrete_palette.getColor(
                    example[self.data_class_index])
            else:
                color = QColor(0, 0, 0)
            self._arrow_lines.append([x, y, z, value, factor, color])
        self._mouseover_called = True
        self.update()
Example #5
0
    def update_data(self, x_attr, y_attr, z_attr,
                    color_attr, symbol_attr, size_attr, label_attr):
        if self.data == None:
            return
        self.before_draw_callback = self.before_draw

        color_discrete = size_discrete = False

        color_index = -1
        if color_attr != '' and color_attr != '(Same color)':
            color_index = self.attribute_name_index[color_attr]
            if self.data_domain[color_attr].varType == Discrete:
                color_discrete = True
                self.discrete_palette.setNumberOfColors(len(self.data_domain[color_attr].values))

        symbol_index = -1
        num_symbols_used = -1
        if symbol_attr != '' and symbol_attr != 'Same symbol)' and\
           len(self.data_domain[symbol_attr].values) < len(Symbol) and\
           self.data_domain[symbol_attr].varType == Discrete:
            symbol_index = self.attribute_name_index[symbol_attr]
            num_symbols_used = len(self.data_domain[symbol_attr].values)

        size_index = -1
        if size_attr != '' and size_attr != '(Same size)':
            size_index = self.attribute_name_index[size_attr]
            if self.data_domain[size_attr].varType == Discrete:
                size_discrete = True

        label_index = -1
        if label_attr != '' and label_attr != '(No labels)':
            label_index = self.attribute_name_index[label_attr]

        x_index = self.attribute_name_index[x_attr]
        y_index = self.attribute_name_index[y_attr]
        z_index = self.attribute_name_index[z_attr]

        x_discrete = self.data_domain[x_attr].varType == Discrete
        y_discrete = self.data_domain[y_attr].varType == Discrete
        z_discrete = self.data_domain[z_attr].varType == Discrete

        colors = []
        if color_discrete:
            for i in range(len(self.data_domain[color_attr].values)):
                c = self.discrete_palette[i]
                colors.append(c)

        data_scale = [self.attr_values[x_attr][1] - self.attr_values[x_attr][0],
                      self.attr_values[y_attr][1] - self.attr_values[y_attr][0],
                      self.attr_values[z_attr][1] - self.attr_values[z_attr][0]]
        data_translation = [self.attr_values[x_attr][0],
                            self.attr_values[y_attr][0],
                            self.attr_values[z_attr][0]]
        data_scale = 1. / numpy.array(data_scale)
        if x_discrete:
            data_scale[0] = 0.5 / float(len(self.data_domain[x_attr].values))
            data_translation[0] = 1.
        if y_discrete:
            data_scale[1] = 0.5 / float(len(self.data_domain[y_attr].values))
            data_translation[1] = 1.
        if z_discrete:
            data_scale[2] = 0.5 / float(len(self.data_domain[z_attr].values))
            data_translation[2] = 1.

        self.data_scale = QVector3D(*data_scale)
        self.data_translation = QVector3D(*data_translation)

        self._x_axis_labels = None
        self._y_axis_labels = None
        self._z_axis_labels = None

        self.clear()

        attr_indices = [x_index, y_index, z_index]
        if color_index > -1:
            attr_indices.append(color_index)
        if size_index > -1:
            attr_indices.append(size_index)
        if symbol_index > -1:
            attr_indices.append(symbol_index)
        if label_index > -1:
            attr_indices.append(label_index)

        valid_data = self.getValidList(attr_indices)
        self.set_valid_data(valid_data)

        self.set_features(x_index, y_index, z_index,
            color_index, symbol_index, size_index, label_index,
            colors, num_symbols_used,
            x_discrete, y_discrete, z_discrete)

        ## Legend
        def_color = QColor(150, 150, 150)
        def_symbol = 0
        def_size = 10

        if color_discrete:
            num = len(self.data_domain[color_attr].values)
            values = get_variable_values_sorted(self.data_domain[color_attr])
            for ind in range(num):
                self.legend().add_item(color_attr, values[ind], OWPoint(def_symbol, self.discrete_palette[ind], def_size))

        if symbol_index != -1:
            num = len(self.data_domain[symbol_attr].values)
            values = get_variable_values_sorted(self.data_domain[symbol_attr])
            for ind in range(num):
                self.legend().add_item(symbol_attr, values[ind], OWPoint(ind, def_color, def_size))

        if size_discrete:
            num = len(self.data_domain[size_attr].values)
            values = get_variable_values_sorted(self.data_domain[size_attr])
            for ind in range(num):
                self.legend().add_item(size_attr, values[ind], OWPoint(def_symbol, def_color, 6 + round(ind * 5 / len(values))))

        if color_index != -1 and self.data_domain[color_attr].varType == Continuous:
            self.legend().add_color_gradient(color_attr, [("%%.%df" % self.data_domain[color_attr].numberOfDecimals % v) for v in self.attr_values[color_attr]])

        self.legend().max_size = QSize(400, 400)
        self.legend().set_floating(True)
        self.legend().set_orientation(Qt.Vertical)
        if self.legend().pos().x() == 0:
            self.legend().setPos(QPointF(100, 100))
        self.legend().update_items()
        self.legend().setVisible(self.show_legend)

        ## Axes
        self._x_axis_title = x_attr
        self._y_axis_title = y_attr
        self._z_axis_title = z_attr

        if x_discrete:
            self._x_axis_labels = get_variable_values_sorted(self.data_domain[x_attr])
        if y_discrete:
            self._y_axis_labels = get_variable_values_sorted(self.data_domain[y_attr])
        if z_discrete:
            self._z_axis_labels = get_variable_values_sorted(self.data_domain[z_attr])

        self.update()
Example #6
0
    def updateData(self, labels=None, setAnchors=0, **args):
        self.clear()
        self.clear_plot_transformations()

        if labels == None:
            labels = [anchor[3] for anchor in self.anchor_data]

        if not self.have_data or len(labels) < 3:
            self.anchor_data = []
            self.update()
            return

        if setAnchors or (args.has_key('XAnchors') and args.has_key('YAnchors')
                          and args.has_key('ZAnchors')):
            self.setAnchors(args.get('XAnchors'), args.get('YAnchors'),
                            args.get('ZAnchors'), labels)

        indices = [
            self.attribute_name_index[anchor[3]] for anchor in self.anchor_data
        ]
        valid_data = self.getValidList(indices)
        trans_proj_data = self.create_projection_as_numeric_array(
            indices,
            validData=valid_data,
            scaleFactor=1.0,
            normalize=self.normalize_examples,
            jitterSize=-1,
            useAnchorData=1,
            removeMissingData=0)
        if trans_proj_data == None:
            return

        proj_data = trans_proj_data.T
        proj_data[0:3] += 0.5
        if self.data_has_discrete_class:
            proj_data[3] = self.no_jittering_scaled_data[
                self.attribute_name_index[self.data_domain.classVar.name]]
        self.set_plot_data(proj_data, None)
        self.proj_data = proj_data
        self.symbol_scale = self.point_width * self._point_width_to_symbol_scale
        self.hide_outside = False
        self.fade_outside = False

        color_index = symbol_index = size_index = label_index = -1
        color_discrete = False
        x_discrete = self.data_domain[self.anchor_data[0]
                                      [3]].varType == Discrete
        y_discrete = self.data_domain[self.anchor_data[1]
                                      [3]].varType == Discrete
        z_discrete = self.data_domain[self.anchor_data[2]
                                      [3]].varType == Discrete

        if self.data_has_discrete_class:
            self.discrete_palette.setNumberOfColors(
                len(self.data_domain.classVar.values))

        use_different_symbols = self.useDifferentSymbols and self.data_has_discrete_class and\
            len(self.data_domain.classVar.values) <= len(Symbol)

        if use_different_symbols:
            symbol_index = 3
            num_symbols_used = len(self.data_domain.classVar.values)
        else:
            num_symbols_used = -1

        if self.useDifferentColors and self.data_has_discrete_class:
            color_discrete = True
            color_index = 3

        colors = []
        if color_discrete:
            for i in range(len(self.data_domain.classVar.values)):
                c = self.discrete_palette[i]
                colors.append(c)

        self.set_features(0, 1, 2, color_index, symbol_index, size_index,
                          label_index, colors, num_symbols_used, x_discrete,
                          y_discrete, z_discrete)

        def_color = QColor(150, 150, 150)
        def_symbol = 0
        def_size = 10

        if color_discrete:
            num = len(self.data_domain.classVar.values)
            values = get_variable_values_sorted(self.data_domain.classVar)
            for ind in range(num):
                symbol = ind if use_different_symbols else def_symbol
                self.legend().add_item(
                    self.data_domain.classVar.name, values[ind],
                    OWPoint(symbol, self.discrete_palette[ind], def_size))

        if use_different_symbols and not color_discrete:
            num = len(self.data_domain.classVar.values)
            values = get_variable_values_sorted(self.data_domain.classVar)
            for ind in range(num):
                self.legend().add_item(self.data_domain.classVar.name,
                                       values[ind],
                                       OWPoint(ind, def_color, def_size))

        self.legend().set_orientation(Qt.Vertical)
        self.legend().max_size = QSize(400, 400)
        if self.legend().pos().x() == 0:
            self.legend().setPos(QPointF(100, 100))
        self.legend().update_items()
        self.legend().setVisible(self.show_legend)

        x_positions = proj_data[0] - 0.5
        y_positions = proj_data[1] - 0.5
        z_positions = proj_data[2] - 0.5
        XAnchors = [anchor[0] for anchor in self.anchor_data]
        YAnchors = [anchor[1] for anchor in self.anchor_data]
        ZAnchors = [anchor[2] for anchor in self.anchor_data]
        data_size = len(self.raw_data)

        value_lines = []
        for i in range(data_size):
            if not valid_data[i]:
                continue
            if self.useDifferentColors and self.data_has_discrete_class:
                color = self.discrete_palette.getRGB(
                    self.original_data[self.data_class_index][i])
            else:
                color = (0, 0, 0)

            len_anchor_data = len(self.anchor_data)
            x = numpy.array([x_positions[i]] * len_anchor_data)
            y = numpy.array([y_positions[i]] * len_anchor_data)
            z = numpy.array([z_positions[i]] * len_anchor_data)
            dists = numpy.sqrt((XAnchors - x)**2 + (YAnchors - y)**2 +
                               (ZAnchors - z)**2)
            x_directions = 0.03 * (XAnchors - x) / dists
            y_directions = 0.03 * (YAnchors - y) / dists
            z_directions = 0.03 * (ZAnchors - z) / dists
            example_values = [
                self.no_jittering_scaled_data[attr_ind, i]
                for attr_ind in indices
            ]

            for j in range(len_anchor_data):
                value_lines.extend([
                    x_positions[i], y_positions[i], z_positions[i],
                    color[0] / 255., color[1] / 255., color[2] / 255., 0., 0.,
                    0., x_positions[i], y_positions[i], z_positions[i],
                    color[0] / 255., color[1] / 255., color[2] / 255.,
                    x_directions[j] * example_values[j],
                    y_directions[j] * example_values[j],
                    z_directions[j] * example_values[j]
                ])

        self._value_lines_buffer = VertexBuffer(
            numpy.array(value_lines, numpy.float32), [(3, GL_FLOAT),
                                                      (3, GL_FLOAT),
                                                      (3, GL_FLOAT)])

        self.update()
Example #7
0
    def set_data(self, data):        
        if data is None or len(data) == 0 or len(data.domain) == 0:
            return
            
        self.data = data
        domain = data.domain
        
        y_i, x_i, c_i, s_i = [int(random.random() * len(domain)) for i in range(4)]
        
        self.plot.set_axis_title(xBottom, domain[x_i].name)
        self.plot.set_show_axis_title(xBottom, True)
        self.plot.set_axis_title(yLeft, domain[y_i].name)
        self.plot.set_show_axis_title(yLeft, True)
        
        if data.domain[x_i].varType == orange.VarTypes.Discrete:
            self.plot.set_axis_labels(xBottom, get_variable_values_sorted(domain[x_i]))
        else:
            self.plot.set_axis_autoscale(xBottom)

        if data.domain[y_i].varType == orange.VarTypes.Discrete:
            self.plot.set_axis_labels(yLeft, get_variable_values_sorted(domain[y_i]))
        else:
            self.plot.set_axis_autoscale(yLeft)
            
        x_data = []
        y_data = []
        c_data = []
        s_data = []
        
        color_cont = (domain[c_i].varType == orange.VarTypes.Continuous)
        
        legend_sizes = set()
        
        for e in data:
            x_data.append(e[x_i])
            y_data.append(e[y_i]) 
            c_data.append(e[c_i])
            size = 5 + round(e[s_i])
            s_data.append(size)
            
            legend_sizes.add( (size, float(e[s_i])) )
            
        if color_cont:
            m = min(c_data)
            M = max(c_data)
            legend_colors = set(float(c) for c in c_data)
            c_data = [self.plot.continuous_palette[(v-m)/(M-m)] for v in c_data]
        else:
            _colors = [self.plot.discrete_palette.getRGB(i) for i in c_data]
            _values = set([float(c) for c in c_data])
            legend_colors = zip([QColor(*c) for c in set(_colors)], _values)
            c_data = [QColor(*c) for c in _colors]
                        
        self.plot.legend().clear()
            
        if domain[s_i].varType == orange.VarTypes.Discrete:
            for size, value in legend_sizes:
                self.plot.legend().add_item( domain[s_i].name, domain[s_i].values[int(value)], OWPoint(OWPoint.Diamond, self.plot.color(OWPalette.Data), size) )
            
        if color_cont:
            self.plot.legend().add_color_gradient(domain[c_i].name, ("%.1f" % min(legend_colors), "%.1f" % max(legend_colors)))
        else:
            for color, value in legend_colors:
                self.plot.legend().add_item( domain[c_i].name, domain[c_i].values[int(value)], OWPoint(OWPoint.Diamond, color, 5) )
                   
        self.plot.set_main_curve_data(x_data, y_data, color_data=c_data, label_data = [], size_data=s_data, shape_data = [OWPoint.Diamond])
        self.plot.replot()
Example #8
0
    def updateData(self, labels=None, setAnchors=0, **args):
        self.clear()
        self.clear_plot_transformations()

        if labels == None:
            labels = [anchor[3] for anchor in self.anchor_data]

        if not self.have_data or len(labels) < 3:
            self.anchor_data = []
            self.update()
            return

        if setAnchors or (args.has_key('XAnchors') and args.has_key('YAnchors') and args.has_key('ZAnchors')):
            self.setAnchors(args.get('XAnchors'), args.get('YAnchors'), args.get('ZAnchors'), labels)

        indices = [self.attribute_name_index[anchor[3]] for anchor in self.anchor_data]
        valid_data = self.getValidList(indices)
        trans_proj_data = self.create_projection_as_numeric_array(indices, validData=valid_data,
            scaleFactor=1.0, normalize=self.normalize_examples, jitterSize=-1,
            useAnchorData=1, removeMissingData=0)
        if trans_proj_data == None:
            return

        proj_data = trans_proj_data.T
        proj_data[0:3] += 0.5
        if self.data_has_discrete_class:
            proj_data[3] = self.no_jittering_scaled_data[self.attribute_name_index[self.data_domain.classVar.name]]
        self.set_plot_data(proj_data, None)
        self.proj_data = proj_data
        self.symbol_scale = self.point_width*self._point_width_to_symbol_scale
        self.hide_outside = False
        self.fade_outside = False

        color_index = symbol_index = size_index = label_index = -1
        color_discrete = False
        x_discrete = self.data_domain[self.anchor_data[0][3]].varType == Discrete
        y_discrete = self.data_domain[self.anchor_data[1][3]].varType == Discrete
        z_discrete = self.data_domain[self.anchor_data[2][3]].varType == Discrete

        if self.data_has_discrete_class:
            self.discrete_palette.setNumberOfColors(len(self.data_domain.classVar.values))

        use_different_symbols = self.useDifferentSymbols and self.data_has_discrete_class and\
            len(self.data_domain.classVar.values) <= len(Symbol)

        if use_different_symbols:
            symbol_index = 3
            num_symbols_used = len(self.data_domain.classVar.values)
        else:
            num_symbols_used = -1

        if self.useDifferentColors and self.data_has_discrete_class:
            color_discrete = True
            color_index = 3

        colors = []
        if color_discrete:
            for i in range(len(self.data_domain.classVar.values)):
                c = self.discrete_palette[i]
                colors.append(c)

        self.set_features(0, 1, 2, color_index, symbol_index, size_index, label_index,
                          colors, num_symbols_used,
                          x_discrete, y_discrete, z_discrete)

        def_color = QColor(150, 150, 150)
        def_symbol = 0
        def_size = 10

        if color_discrete:
            num = len(self.data_domain.classVar.values)
            values = get_variable_values_sorted(self.data_domain.classVar)
            for ind in range(num):
                symbol = ind if use_different_symbols else def_symbol
                self.legend().add_item(self.data_domain.classVar.name, values[ind], OWPoint(symbol, self.discrete_palette[ind], def_size))

        if use_different_symbols and not color_discrete:
            num = len(self.data_domain.classVar.values)
            values = get_variable_values_sorted(self.data_domain.classVar)
            for ind in range(num):
                self.legend().add_item(self.data_domain.classVar.name, values[ind], OWPoint(ind, def_color, def_size))

        self.legend().set_orientation(Qt.Vertical)
        self.legend().max_size = QSize(400, 400)
        if self.legend().pos().x() == 0:
            self.legend().setPos(QPointF(100, 100))
        self.legend().update_items()
        self.legend().setVisible(self.show_legend)

        x_positions = proj_data[0]-0.5
        y_positions = proj_data[1]-0.5
        z_positions = proj_data[2]-0.5
        XAnchors = [anchor[0] for anchor in self.anchor_data]
        YAnchors = [anchor[1] for anchor in self.anchor_data]
        ZAnchors = [anchor[2] for anchor in self.anchor_data]
        data_size = len(self.raw_data)

        value_lines = []
        for i in range(data_size):
            if not valid_data[i]:
                continue
            if self.useDifferentColors and self.data_has_discrete_class:
                color = self.discrete_palette.getRGB(self.original_data[self.data_class_index][i])
            else:
                color = (0, 0, 0)

            len_anchor_data = len(self.anchor_data)
            x = numpy.array([x_positions[i]] * len_anchor_data)
            y = numpy.array([y_positions[i]] * len_anchor_data)
            z = numpy.array([z_positions[i]] * len_anchor_data)
            dists = numpy.sqrt((XAnchors - x)**2 + (YAnchors - y)**2 + (ZAnchors - z)**2)
            x_directions = 0.03 * (XAnchors - x) / dists
            y_directions = 0.03 * (YAnchors - y) / dists
            z_directions = 0.03 * (ZAnchors - z) / dists
            example_values = [self.no_jittering_scaled_data[attr_ind, i] for attr_ind in indices]

            for j in range(len_anchor_data):
                value_lines.extend([x_positions[i], y_positions[i], z_positions[i],
                                    color[0]/255.,
                                    color[1]/255.,
                                    color[2]/255.,
                                    0., 0., 0.,
                                    x_positions[i], y_positions[i], z_positions[i],
                                    color[0]/255.,
                                    color[1]/255.,
                                    color[2]/255.,
                                    x_directions[j]*example_values[j],
                                    y_directions[j]*example_values[j],
                                    z_directions[j]*example_values[j]])

        self._value_lines_buffer = VertexBuffer(numpy.array(value_lines, numpy.float32),
            [(3, GL_FLOAT),
             (3, GL_FLOAT),
             (3, GL_FLOAT)])

        self.update()
Example #9
0
    def set_data(self, data):
        if data is None or len(data) == 0 or len(data.domain) == 0:
            return

        self.data = data
        domain = data.domain

        y_i, x_i, c_i, s_i = [
            int(random.random() * len(domain)) for i in range(4)
        ]

        self.plot.set_axis_title(xBottom, domain[x_i].name)
        self.plot.set_show_axis_title(xBottom, True)
        self.plot.set_axis_title(yLeft, domain[y_i].name)
        self.plot.set_show_axis_title(yLeft, True)

        if data.domain[x_i].varType == orange.VarTypes.Discrete:
            self.plot.set_axis_labels(xBottom,
                                      get_variable_values_sorted(domain[x_i]))
        else:
            self.plot.set_axis_autoscale(xBottom)

        if data.domain[y_i].varType == orange.VarTypes.Discrete:
            self.plot.set_axis_labels(yLeft,
                                      get_variable_values_sorted(domain[y_i]))
        else:
            self.plot.set_axis_autoscale(yLeft)

        x_data = []
        y_data = []
        c_data = []
        s_data = []

        color_cont = (domain[c_i].varType == orange.VarTypes.Continuous)

        legend_sizes = set()

        for e in data:
            x_data.append(e[x_i])
            y_data.append(e[y_i])
            c_data.append(e[c_i])
            size = 5 + round(e[s_i])
            s_data.append(size)

            legend_sizes.add((size, float(e[s_i])))

        if color_cont:
            m = min(c_data)
            M = max(c_data)
            legend_colors = set(float(c) for c in c_data)
            c_data = [
                self.plot.continuous_palette[(v - m) / (M - m)] for v in c_data
            ]
        else:
            _colors = [self.plot.discrete_palette.getRGB(i) for i in c_data]
            _values = set([float(c) for c in c_data])
            legend_colors = zip([QColor(*c) for c in set(_colors)], _values)
            c_data = [QColor(*c) for c in _colors]

        self.plot.legend().clear()

        if domain[s_i].varType == orange.VarTypes.Discrete:
            for size, value in legend_sizes:
                self.plot.legend().add_item(
                    domain[s_i].name, domain[s_i].values[int(value)],
                    OWPoint(OWPoint.Diamond, self.plot.color(OWPalette.Data),
                            size))

        if color_cont:
            self.plot.legend().add_color_gradient(
                domain[c_i].name,
                ("%.1f" % min(legend_colors), "%.1f" % max(legend_colors)))
        else:
            for color, value in legend_colors:
                self.plot.legend().add_item(domain[c_i].name,
                                            domain[c_i].values[int(value)],
                                            OWPoint(OWPoint.Diamond, color, 5))

        self.plot.set_main_curve_data(x_data,
                                      y_data,
                                      color_data=c_data,
                                      label_data=[],
                                      size_data=s_data,
                                      shape_data=[OWPoint.Diamond])
        self.plot.replot()