def test_rgb_to_hex(self): # provided by http://en.labelpartners.com/pantone_coated_table.html matches = [[(254, 221, 0), "#FEDD00"], [(0, 20, 137), "#001489"], [(175, 152, 0), "#AF9800"], [(255, 127, 50), "#FF7F32"]] for rgb, hex_code in matches: self.assertEqual(rgb_to_hex(rgb).lower(), hex_code.lower())
def gradient_color(self): if not self.is_logistic: return self.default_background_color else: target_class_idx = self.data.domain.class_var.values.\ index(self.target_class) color = self.data.domain.class_var.colors[target_class_idx] return rgb_to_hex(tuple(color))
def gradient_color(self): if not self.is_logistic: return self.default_background_color else: target_class_idx = self.data.domain.class_var.values.\ index(self.target_class) color = self.data.domain.class_var.colors[target_class_idx] return rgb_to_hex(tuple(color))
def test_rgb_to_hex(self): # provided by http://en.labelpartners.com/pantone_coated_table.html matches = [[(254, 221, 0), "#FEDD00"], [(0, 20, 137), "#001489"], [(175, 152, 0), "#AF9800"], [(255, 127, 50), "#FF7F32"]] for rgb, hex_code in matches: self.assertEqual(rgb_to_hex(rgb).lower(), hex_code.lower())
def replot(self): """ This function performs complete replot of the graph """ if self.data is None or self.selected_data is None: self.set_empty_plot() return attr_x = self.data.domain[self.attr_x] attr_y = self.data.domain[self.attr_y] data_x = [v[0] for v in self.data[:, attr_x] if not isnan(v[0])] data_y = [v[0] for v in self.data[:, attr_y] if not isnan(v[0])] min_x = min(data_x) max_x = max(data_x) min_y = min(data_y) max_y = max(data_y) # just in cas that diff is 0 diff_x = (max_x - min_x) if abs(max_x - min_x) > 0.001 else 0.1 diff_y = (max_y - min_y) if abs(max_y - min_y) > 0.001 else 0.1 min_x, max_x = min_x - 0.03 * diff_x, max_x + 0.03 * diff_x min_y, max_y = min_y - 0.03 * diff_y, max_y + 0.03 * diff_y options = dict(series=[]) # gradient and contour options['series'] += self.plot_gradient_and_contour( min_x, max_x, min_y, max_y) sd = self.selected_data # data points options['series'] += [ dict( data=[list(p.attributes()) for p in sd if (int(p.metas[0]) == _class and all(v is not None for v in p.attributes()))], type="scatter", zIndex=10, color=rgb_to_hex(tuple( sd.domain.metas[0].colors[_class].tolist())), showInLegend=True, name=sd.domain.metas[0].values[_class]) for _class in range(len(sd.domain.metas[0].values))] cls_domain = sd.domain.metas[0] target_idx = cls_domain.values.index(self.target_class) target_color = tuple(cls_domain.colors[target_idx].tolist()) other_color = (tuple(cls_domain.colors[(target_idx + 1) % 2].tolist()) if len(cls_domain.values) == 2 else (170, 170, 170)) # highcharts parameters kwargs = dict( xAxis_title_text=attr_x.name, yAxis_title_text=attr_y.name, xAxis_min=min_x, xAxis_max=max_x, yAxis_min=min_y, yAxis_max=max_y, colorAxis=dict( labels=dict(enabled=False), stops=[ [0, rgb_hash_brighter(rgb_to_hex(other_color), 0.5)], [0.5, '#ffffff'], [1, rgb_hash_brighter(rgb_to_hex(target_color), 0.5)]], tickInterval=0.2, min=0, max=1), plotOptions_contour_colsize=(max_y - min_y) / 1000, plotOptions_contour_rowsize=(max_x - min_x) / 1000, legend=dict( enabled=self.legend_enabled, layout='vertical', align='right', verticalAlign='top', floating=True, backgroundColor='rgba(255, 255, 255, 0.3)', symbolWidth=0, symbolHeight=0), tooltip_headerFormat="", tooltip_pointFormat="<strong>%s:</strong> {point.x:.2f} <br/>" "<strong>%s:</strong> {point.y:.2f}" % (self.attr_x, self.attr_y)) self.scatter.chart(options, **kwargs) self.plot_contour()
def replot(self): """ This function performs complete replot of the graph """ if self.data is None or self.selected_data is None: self.set_empty_plot() return attr_x = self.data.domain[self.attr_x] attr_y = self.data.domain[self.attr_y] data_x = [v[0] for v in self.data[:, attr_x] if not isnan(v[0])] data_y = [v[0] for v in self.data[:, attr_y] if not isnan(v[0])] min_x = min(data_x) max_x = max(data_x) min_y = min(data_y) max_y = max(data_y) # just in cas that diff is 0 diff_x = (max_x - min_x) if abs(max_x - min_x) > 0.001 else 0.1 diff_y = (max_y - min_y) if abs(max_y - min_y) > 0.001 else 0.1 min_x, max_x = min_x - 0.03 * diff_x, max_x + 0.03 * diff_x min_y, max_y = min_y - 0.03 * diff_y, max_y + 0.03 * diff_y options = dict(series=[]) # gradient and contour options['series'] += self.plot_gradient_and_contour( min_x, max_x, min_y, max_y) sd = self.selected_data # data points options['series'] += [ dict(data=[ list(p.attributes()) for p in sd if (p.metas[0] == _class and all(v is not None for v in p.attributes())) ], type="scatter", zIndex=10, color=rgb_to_hex( tuple(sd.domain.metas[0].colors[_class].tolist())), showInLegend=True, name=sd.domain.metas[0].values[_class]) for _class in range(len(sd.domain.metas[0].values)) ] # add nan values as a gray dots options['series'] += [ dict(data=[ list(p.attributes()) for p in sd if np.isnan(p.metas[0]) ], type="scatter", zIndex=10, color=rgb_to_hex((160, 160, 160)), showInLegend=False) ] cls_domain = sd.domain.metas[0] target_idx = cls_domain.values.index(self.target_class) target_color = tuple(cls_domain.colors[target_idx].tolist()) other_color = (tuple(cls_domain.colors[(target_idx + 1) % 2].tolist()) if len(cls_domain.values) == 2 else (170, 170, 170)) # highcharts parameters kwargs = dict( xAxis_title_text=attr_x.name, yAxis_title_text=attr_y.name, xAxis_min=min_x, xAxis_max=max_x, yAxis_min=min_y, yAxis_max=max_y, colorAxis=dict( labels=dict(enabled=False), stops=[[0, rgb_hash_brighter(rgb_to_hex(other_color), 0.5)], [0.5, '#ffffff'], [1, rgb_hash_brighter(rgb_to_hex(target_color), 0.5)]], tickInterval=0.2, min=0, max=1), plotOptions_contour_colsize=(max_y - min_y) / 1000, plotOptions_contour_rowsize=(max_x - min_x) / 1000, legend=dict(enabled=self.legend_enabled, layout='vertical', align='right', verticalAlign='top', floating=True, backgroundColor='rgba(255, 255, 255, 0.3)', symbolWidth=0, symbolHeight=0), tooltip_headerFormat="", tooltip_pointFormat="<strong>%s:</strong> {point.x:.2f} <br/>" "<strong>%s:</strong> {point.y:.2f}" % (self.attr_x, self.attr_y)) self.scatter.chart(options, **kwargs) self.plot_contour()