def OnGridColor(self,event): dlg = wx.ColourDialog(self) if dlg.ShowModal() == wx.ID_OK: color = dlg.GetColourData().Colour r,g,b = color.Red(),color.Green(),color.Blue() self.axes.grid(color=rgb2hex(r,g,b)) dlg.Destroy() self.canvas.draw()
def OnBackground(self,event): dlg = wx.ColourDialog(self) if dlg.ShowModal() == wx.ID_OK: color = dlg.GetColourData().Colour r,g,b = color.Red(),color.Green(),color.Blue() self.axes.set_axis_bgcolor(rgb2hex(r,g,b)) dlg.Destroy() self.canvas.draw()
def set_line_color(self,event): dlg = wx.ColourDialog(self) if dlg.ShowModal() == wx.ID_OK: color = dlg.GetColourData().Colour r,g,b = color.Red(),color.Green(),color.Blue() event.artist.set_color(rgb2hex(r,g,b)) dlg.Destroy() self.canvas.draw() self.canvas.mpl_disconnect(self.LINE_COLOR_EVT)
def __init__(self, num_hues=8, sat_range=2, light_range=2): height = 1 + sat_range + (2 * light_range - 1) # generate num_hues+1 hues, but don't take the last one: # hues are on a circle, and we would be oversampling the origin hues = np.tile(np.linspace(0, 1, num_hues + 1)[:-1], (height, 1)) if num_hues == 8: hues = np.tile(np.array( [0., 0.10, 0.15, 0.28, 0.51, 0.58, 0.77, 0.85]), (height, 1)) if num_hues == 9: hues = np.tile(np.array( [0., 0.10, 0.15, 0.28, 0.49, 0.54, 0.60, 0.7, 0.87]), (height, 1)) if num_hues == 10: hues = np.tile(np.array( [0., 0.10, 0.15, 0.28, 0.49, 0.54, 0.60, 0.66, 0.76, 0.87]), (height, 1)) elif num_hues == 11: hues = np.tile(np.array( [0.0, 0.0833, 0.166, 0.25, 0.333, 0.5, 0.56333, 0.666, 0.73, 0.803, 0.916]), (height, 1)) sats = np.hstack(( np.linspace(0, 1, sat_range + 2)[1:-1], 1, [1] * (light_range), [.4] * (light_range - 1), )) lights = np.hstack(( [1] * sat_range, 1, np.linspace(1, 0.2, light_range + 2)[1:-1], np.linspace(1, 0.2, light_range + 2)[1:-2], )) sats = np.tile(np.atleast_2d(sats).T, (1, num_hues)) lights = np.tile(np.atleast_2d(lights).T, (1, num_hues)) colors = hsv2rgb(np.dstack((hues, sats, lights))) grays = np.tile( np.linspace(1, 0, height)[:, np.newaxis, np.newaxis], (1, 1, 3)) self.rgb_image = np.hstack((colors, grays)) # Make a nice histogram ordering of the hues and grays h, w, d = colors.shape color_array = colors.T.reshape((d, w * h)).T h, w, d = grays.shape gray_array = grays.T.reshape((d, w * h)).T self.rgb_array = np.vstack((color_array, gray_array)) self.lab_array = rgb2lab(self.rgb_array[None, :, :]).squeeze() self.hex_list = [rgb2hex(row) for row in self.rgb_array] #assert(np.all(self.rgb_array == self.rgb_array[None, :, :].squeeze())) self.distances = euclidean_distances(self.lab_array, squared=True)
def make_color_ramp(canvas, start_point, r_ramp, g_ramp, b_ramp, n_steps, ramp_height): r_shift = get_color_shift(r_ramp, n_steps) g_shift = get_color_shift(g_ramp, n_steps) b_shift = get_color_shift(b_ramp, n_steps) for step in range(n_steps): r_val = get_ramp_val_at_step(r_ramp, r_shift, step) g_val = get_ramp_val_at_step(g_ramp, g_shift, step) b_val = get_ramp_val_at_step(b_ramp, b_shift, step) color = rgb2hex(r_val, g_val, b_val) canvas.create_line(start_point.x + step, start_point.y, start_point.x + step, start_point.y + ramp_height, fill=color, width=1) return start_point.x + n_steps
def get_palette_html(): """ Return HTML for a color picker using the given palette. """ html = """ <style> span { width: 20px; height: 20px; margin: 2px; padding: 0px; display: inline-block; } </style> """ for row in self.rgb_image: for rgb_color in row: s = '<a id="{0}"><span style="background-color: {0}" /></a>\n' html += s.format(rgb2hex(rgb_color)) html += "<br />\n" return html
def __init__(self, num_hues=8, sat_range=2, light_range=2): height = 1 + sat_range + (2 * light_range - 1) # generate num_hues+1 hues, but don't take the last one: # hues are on a circle, and we would be oversampling the origin hues = np.tile(np.linspace(0, 1, num_hues + 1)[:-1], (height, 1)) if num_hues == 8: hues = np.tile(np.array([0.0, 0.10, 0.15, 0.28, 0.51, 0.58, 0.77, 0.85]), (height, 1)) if num_hues == 9: hues = np.tile(np.array([0.0, 0.10, 0.15, 0.28, 0.49, 0.54, 0.60, 0.7, 0.87]), (height, 1)) if num_hues == 10: hues = np.tile(np.array([0.0, 0.10, 0.15, 0.28, 0.49, 0.54, 0.60, 0.66, 0.76, 0.87]), (height, 1)) elif num_hues == 11: hues = np.tile( np.array([0.0, 0.0833, 0.166, 0.25, 0.333, 0.5, 0.56333, 0.666, 0.73, 0.803, 0.916]), (height, 1) ) sats = np.hstack((np.linspace(0, 1, sat_range + 2)[1:-1], 1, [1] * (light_range), [0.4] * (light_range - 1))) lights = np.hstack( ([1] * sat_range, 1, np.linspace(1, 0.2, light_range + 2)[1:-1], np.linspace(1, 0.2, light_range + 2)[1:-2]) ) sats = np.tile(np.atleast_2d(sats).T, (1, num_hues)) lights = np.tile(np.atleast_2d(lights).T, (1, num_hues)) colors = hsv2rgb(np.dstack((hues, sats, lights))) grays = np.tile(np.linspace(1, 0, height)[:, np.newaxis, np.newaxis], (1, 1, 3)) self.rgb_image = np.hstack((colors, grays)) # Make a nice histogram ordering of the hues and grays h, w, d = colors.shape color_array = colors.T.reshape((d, w * h)).T h, w, d = grays.shape gray_array = grays.T.reshape((d, w * h)).T self.rgb_array = np.vstack((color_array, gray_array)) self.lab_array = rgb2lab(self.rgb_array[None, :, :]).squeeze() self.hex_list = [rgb2hex(row) for row in self.rgb_array] # assert(np.all(self.rgb_array == self.rgb_array[None, :, :].squeeze())) self.distances = euclidean_distances(self.lab_array, squared=True)