コード例 #1
0
    def get_style(self, simple=False):
        ret = {
            "stroke_opacity": self.get_stroke_opacity(),
            "stroke_width": self.get_stroke_width(),
        }

        if simple:
            ret["fill_color"] = colour.rgb2hex(self.get_fill_color().get_rgb())
            ret["fill_opacity"] = self.get_fill_opacity()
            ret["stroke_color"] = colour.rgb2hex(
                self.get_stroke_color().get_rgb())
        else:
            ret["fill_color"] = self.get_fill_colors()
            ret["fill_opacity"] = self.get_fill_opacities()
            ret["stroke_color"] = self.get_stroke_colors()
            ret["background_stroke_color"] = self.get_stroke_colors(
                background=True)
            ret["background_stroke_width"] = self.get_stroke_width(
                background=True)
            ret["background_stroke_opacity"] = self.get_stroke_opacity(
                background=True)
            ret["sheen_factor"] = self.get_sheen_factor()
            ret["sheen_direction"] = self.get_sheen_direction()
            ret["background_image_file"] = self.get_background_image_file()

        return ret
コード例 #2
0
ファイル: dm.py プロジェクト: rohanmodil123/OrionGreeter
def fade(widget, smoothness=3, cnf={}, **kw):
    """This function will show faded effect on widget's different color options.

    Args:
        widget (tk.Widget): Passed by the bind function.
        smoothness (int): Set the smoothness of the fading (1-10).
        background (str): Fade background color to.
        foreground (str): Fade foreground color to."""

    kw = tk._cnfmerge((cnf, kw))
    if not kw: raise ValueError("No option given, -bg, -fg, etc")
    if len(kw) > 1:
        return [fade(widget, smoothness, {k: v}) for k, v in kw.items()][0]
    if not getattr(widget, '_after_ids', None): widget._after_ids = {}
    widget.after_cancel(widget._after_ids.get(list(kw)[0], ' '))
    c1 = tuple(map(lambda a: a / 65535, widget.winfo_rgb(widget[list(kw)[0]])))
    c2 = tuple(map(lambda a: a / 65535,
                   widget.winfo_rgb(list(kw.values())[0])))
    colors = tuple(
        colour.rgb2hex(c, force_long=True)
        for c in colour.color_scale(c1, c2, max(1, smoothness * 15)))

    def worker(count=0):
        if len(colors) - 1 <= count: return
        widget.config({list(kw)[0]: colors[count]})
        widget._after_ids.update({
            list(kw)[0]:
            widget.after(max(1, int(smoothness / 10)), worker, count + 1)
        })

    worker()
コード例 #3
0
ファイル: utilities.py プロジェクト: wassemalward/cegaltools
 def _global_colorscheme():
     colorscheme = []
     for color in px.colors.qualitative.Vivid:
         rgb_string = re.findall(r'\d+', color)
         rgb_tuple = tuple(int(i) for i in rgb_string)
         colorscheme.append(rgb2hex(rgb_tuple)[:7])
     return colorscheme
コード例 #4
0
ファイル: trees.py プロジェクト: michaelyyq/dtreeviz
def rtreeviz_bivar_heatmap(ax, X_train, y_train, max_depth, feature_names,
                           fontsize=14, ticks_fontsize=12, fontname="Arial",
                           show={'title'},
                           n_colors_in_map=100,
                           colors=None
                           ) -> tree.DecisionTreeClassifier:
    """
    Show tesselated 2D feature space for bivariate regression tree. X_train can
    have lots of features but features lists indexes of 2 features to train tree with.
    """
    if isinstance(X_train,pd.DataFrame):
        X_train = X_train.values
    if isinstance(y_train, pd.Series):
        y_train = y_train.values

    colors = adjust_colors(colors)

    rt = tree.DecisionTreeRegressor(max_depth=max_depth)
    rt.fit(X_train, y_train)

    y_lim = np.min(y_train), np.max(y_train)
    y_range = y_lim[1] - y_lim[0]
    color_map = [rgb2hex(c.rgb, force_long=True) for c in Color(colors['color_map_min']).range_to(Color(colors['color_map_max']),
                                                                                                  n_colors_in_map)]

    shadow_tree = ShadowDecTree(rt, X_train, y_train, feature_names=feature_names)

    tesselation = shadow_tree.tesselation()

    for node,bbox in tesselation:
        pred = node.prediction()
        color = color_map[int(((pred - y_lim[0]) / y_range) * (n_colors_in_map-1))]
        x = bbox[0]
        y = bbox[1]
        w = bbox[2] - bbox[0]
        h = bbox[3] - bbox[1]
        rect = patches.Rectangle((x, y), w, h, 0, linewidth=.3, alpha=.5,
                                 edgecolor=colors['edge'], facecolor=color)
        ax.add_patch(rect)

    color_map = [color_map[int(((y-y_lim[0])/y_range)*(n_colors_in_map-1))] for y in y_train]
    x, y, z = X_train[:,0], X_train[:,1], y_train
    ax.scatter(x, y, marker='o', alpha=.95, c=color_map, edgecolor=colors['scatter_edge'], lw=.3)

    ax.set_xlabel(f"{feature_names[0]}", fontsize=fontsize, fontname=fontname, color=colors['axis_label'])
    ax.set_ylabel(f"{feature_names[1]}", fontsize=fontsize, fontname=fontname, color=colors['axis_label'])

    ax.tick_params(axis='both', which='major', width=.3, labelcolor=colors['tick_label'], labelsize=ticks_fontsize)

    if 'title' in show:
        accur = rt.score(X_train, y_train)
        title = f"Regression tree depth {max_depth}, training $R^2$={accur:.3f}"
        plt.title(title, fontsize=fontsize, color=colors['title'])

    return None
コード例 #5
0
ファイル: color.py プロジェクト: PredaaA/Toxic-Cogs
 async def build_embed(self, co):
     rgb = [int(c * 255) for c in co.rgb]
     rgb = tuple(rgb)
     file = await self.bot.loop.run_in_executor(None, self.have_fun_with_pillow, rgb)
     hexa = rgb2hex(co.rgb, force_long=True)
     embed = discord.Embed(
         title=f"Color Embed for: {hexa}", color=int(hexa.replace("#", "0x"), 0)
     )
     embed.add_field(name="Hexadecimal Value:", value=hexa)
     normal = ", ".join([f"{part:.2f}" for part in co.rgb])
     extended = ", ".join([f"{(part*255):.2f}" for part in co.rgb])
     embed.add_field(name="Red, Green, Blue (RGB) Value: ", value=f"{normal}\n{extended}")
     embed.add_field(name="Hue, Saturation, Luminance (HSL) Value:", value=str(co.hsl))
     embed.set_thumbnail(url="attachment://picture.png")
     return embed, file
コード例 #6
0
    def update_hsv(self, *args):
        h = self.hue.get() / 360.0
        s = self.sat.get()
        v = self.var.get()
        hsv = (h, s, v)
        print(hsv)
        rgb = colorsys.hsv_to_rgb(h, s, v)
        print(rgb)
        hex_colour = colour.rgb2hex(rgb, force_long=True)
        print(hex_colour)
        self.canvas.configure(background=hex_colour)

        self.init_light()

        self.light.set_hsv(hsv)
コード例 #7
0
ファイル: Mezcal.py プロジェクト: embiblio/Mezcal
	def cb4( self, color, dontconvert=False ):
		if isinstance( color, str ):
			regex = re.compile( r'^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$', re.IGNORECASE )
			if regex.match( color ):
				if dontconvert is False:
					rgb = colour.hex2rgb( color )
					color = colour.rgb2hsv( rgb )
				else:
					print("pass")
					return color
			else:
				return "hexidecimal:", color, "isn't a hexidecimal"
		elif isinstance( color, list ):
			rgb = colour.hsv2rgb(  tuple( color[:3] ) )
			color = colour.rgb2hex( rgb, force_long=True )
		else:
				return False
		return color
コード例 #8
0
def color_fade(widget, **kw):
    if not getattr(widget, '_after_ids', None):
        widget._after_ids = {}

    widget.after_cancel(widget._after_ids.get(list(kw)[0], ' '))

    color_a = tuple(c / 65535 for c in widget.winfo_rgb(widget[list(kw)[0]]))
    color_b = tuple(c / 65535 for c in widget.winfo_rgb(list(kw.values())[0]))

    colors = tuple(
        colour.rgb2hex(color, force_long=True)
        for color in colour.color_scale(color_a, color_b, 70))

    def update_widget_after(count=0):
        if len(colors) - 1 <= count:
            return

        else:
            widget.config({list(kw)[0]: colors[count]})
            widget._after_ids.update(
                {list(kw)[0]: widget.after(1, update_widget_after, count + 1)})

    update_widget_after()
コード例 #9
0
 def get_style(self):
     return {
         "fill_color": colour.rgb2hex(self.color.get_rgb()),
         "fill_opacity": self.fill_opacity,
     }
コード例 #10
0
ファイル: trees.py プロジェクト: michaelyyq/dtreeviz
def rtreeviz_bivar_3D(ax, X_train, y_train, max_depth, feature_names, target_name,
                      fontsize=14, ticks_fontsize=10, fontname="Arial",
                      azim=0, elev=0, dist=7,
                      show={'title'},
                      colors=None,
                      n_colors_in_map = 100
                      ) -> tree.DecisionTreeClassifier:
    """
    Show 3D feature space for bivariate regression tree. X_train can
    have lots of features but features lists indexes of 2 features to train tree with.
    """
    if isinstance(X_train, pd.DataFrame):
        X_train = X_train.values
    if isinstance(y_train, pd.Series):
        y_train = y_train.values

    colors = adjust_colors(colors)

    ax.view_init(elev=elev, azim=azim)
    ax.dist = dist

    def plane(node, bbox):
        x = np.linspace(bbox[0], bbox[2], 2)
        y = np.linspace(bbox[1], bbox[3], 2)
        xx, yy = np.meshgrid(x, y)
        z = np.full(xx.shape, node.prediction())
        # print(f"{node.prediction()}->{int(((node.prediction()-y_lim[0])/y_range)*(n_colors_in_map-1))}, lim {y_lim}")
        # print(f"{color_map[int(((node.prediction()-y_lim[0])/y_range)*(n_colors_in_map-1))]}")
        ax.plot_surface(xx, yy, z, alpha=.85, shade=False,
                        color=color_map[int(((node.prediction()-y_lim[0])/y_range)*(n_colors_in_map-1))],
                        edgecolor=colors['edge'], lw=.3)

    rt = tree.DecisionTreeRegressor(max_depth=max_depth)
    rt.fit(X_train, y_train)

    y_lim = np.min(y_train), np.max(y_train)
    y_range = y_lim[1] - y_lim[0]
    color_map = [rgb2hex(c.rgb, force_long=True) for c in Color(colors['color_map_min']).range_to(Color(colors['color_map_max']),
                                                                                                  n_colors_in_map)]
    color_map = [color_map[int(((y-y_lim[0])/y_range)*(n_colors_in_map-1))] for y in y_train]

    shadow_tree = ShadowDecTree(rt, X_train, y_train, feature_names=feature_names)
    tesselation = shadow_tree.tesselation()

    for node, bbox in tesselation:
        plane(node, bbox)

    x, y, z = X_train[:, 0], X_train[:, 1], y_train
    ax.scatter(x, y, z, marker='o', alpha=.7, edgecolor=colors['scatter_edge'], lw=.3, c=color_map)

    ax.set_xlabel(f"{feature_names[0]}", fontsize=fontsize, fontname=fontname, color=colors['axis_label'])
    ax.set_ylabel(f"{feature_names[1]}", fontsize=fontsize, fontname=fontname, color=colors['axis_label'])
    ax.set_zlabel(f"{target_name}", fontsize=fontsize, fontname=fontname, color=colors['axis_label'])

    ax.tick_params(axis='both', which='major', width=.3, labelcolor=colors['tick_label'], labelsize=ticks_fontsize)

    if 'title' in show:
        accur = rt.score(X_train, y_train)
        title = f"Regression tree depth {max_depth}, training $R^2$={accur:.3f}"
        plt.title(title, fontsize=fontsize, color=colors['title'])

    return None
コード例 #11
0
 def set(self, col):
     hx = rgb2hex(col[0],col[1],col[2])
     self['bg'] = hx
コード例 #12
0
 def set(self, colours):
     self.reduce_colours(0)
     for col in colours:
         hx = rgb2hex(col[0],col[1],col[2])
         self._add_colour(hx)
     self.update()
コード例 #13
0
def rgb_to_hex(rgb: Iterable[float]) -> str:
    return rgb2hex(rgb, force_long=True).upper()
コード例 #14
0
    def convert_rgb_to_hex(self, rgb_code):
        # Creats a tuple
        t = (int(rgb_code[0]), int(rgb_code[1]), int(rgb_code[2]))

        return colour.rgb2hex(t, force_long=True)
コード例 #15
0
    def convert_hsv_to_hex(self, hsv_code):
        rgb_code = colorsys.hsv_to_rgb(float(hsv_code[0]), float(hsv_code[1]),
                                       float(hsv_code[2]))

        return colour.rgb2hex(rgb_code, force_long=True)