Returns a list of colors with the same distributed spread as used in ggplot2 (color wheel) but shaken up a little
       so that adjacent series have differing hues for larger values of n.
330978
def get_spaced_plot_colors(n, start = 45, saturation_adjustment = 0.7, saturation = 0.65, lightness = 1.0, prefix = ''):
    ''''''

    assert (n > 0)
    if n <= 5:
        # For small n, the color wheel will generate colors which naturally differ
        return ggplot_color_wheel(n, start = start, saturation_adjustment = saturation_adjustment, saturation = saturation, lightness = lightness, prefix = prefix)
    else:
        # For larger values of n, generate n colors spaced
        plot_colors = ggplot_color_wheel(n, start = start, saturation_adjustment = saturation_adjustment, saturation = saturation, lightness = lightness, prefix = prefix)
        hp = dumb_relative_half_prime(n)
        color_wheel = [plot_colors[x % n] for x in range(0, hp * n, hp)]
        if not len(color_wheel) == len(set(color_wheel)):
            raise Exception('The color wheel was not generated correctly. Are {0} and {1} relatively prime?'.format(n, hp))
        return color_wheel
519525
def colors_to_needle_positions(rows):
    
    needles = []
    for row in rows:
        colors = set(row)
        if len(colors) == 1:
            needles.append([NeedlePositions(row, tuple(colors), False)])
        elif len(colors) == 2:
            color1, color2 = colors
            if color1 != row[0]:
                color1, color2 = color2, color1
            needles_ = _row_color(row, color1)
            needles.append([NeedlePositions(needles_, (color1, color2), True)])
        else:
            colors = []
            for color in row:
                if color not in colors:
                    colors.append(color)
            needles_ = []
            for color in colors:
                needles_.append(NeedlePositions(_row_color(row, color),
                                                (color,), False))
            needles.append(needles_)
    return needles
1075885
def assign_colors(dir_counts):
    ''''''
    frequencies = map(lambda x: x[1],dir_counts)
    words = map(lambda x: x[0],dir_counts)
    maxoccur = max(frequencies)
    minoccur = min(frequencies)
    colors = map(lambda x: colorize(x,maxoccur,minoccur),frequencies)
    color_dict = dict(zip(words,colors))
    return color_dict
658597
def diff_colormap():
    ""

    # bottom = plt.cm.copper(np.linspace(0., 1, 6))
    black = np.atleast_2d([0., 0., 0., 1.])
    bottom = np.repeat(black, 6, axis=0)
    middle = plt.cm.copper(np.linspace(0, 1, 250))
    # remain = plt.cm.Reds(np.linspace(0, 1, 240))

    colors = np.vstack((bottom, middle))
    diff_colormap = mpl.colors.LinearSegmentedColormap.from_list('diff_colormap', colors)

    return diff_colormap
119448
def getcolors(spec, n, cmap=None, value=None):
    
    if cmap is not None and spec is not None:
        from matplotlib.colors import LinearSegmentedColormap
        from matplotlib.cm import get_cmap
        if isinstance(cmap, LinearSegmentedColormap):
            return cmap(value)[:, 0:3]
        if isinstance(cmap, str):
            return get_cmap(cmap, n)(value)[:, 0:3]
    if isinstance(spec, str):
        return [getcolor(spec) for i in range(n)]
    elif isinstance(spec, list) and isinstance(spec[0], str):
        return [getcolor(s) for s in spec]
    elif (isinstance(spec, list) or isinstance(spec, ndarray)) and asarray(spec).shape == (3,):
        return [spec for i in range(n)]
    else:
        return spec
904754
def _svgcolor(color):
    
    return 'rgb(%d,%d,%d)' % tuple([int(255 * x) for x in [color.r, color.g, color.b]])
659552
def _build_color_table():
        
        FG = FOREGROUND_COLOR
        BG = BACKROUND_COLOR

        return [
            (0x00, 0x00, 0x00, FG.BLACK, BG.BLACK),
            (0x00, 0x00, 0xaa, FG.BLUE, BG.BLUE),
            (0x00, 0xaa, 0x00, FG.GREEN, BG.GREEN),
            (0x00, 0xaa, 0xaa, FG.CYAN, BG.CYAN),
            (0xaa, 0x00, 0x00, FG.RED, BG.RED),
            (0xaa, 0x00, 0xaa, FG.MAGENTA, BG.MAGENTA),
            (0xaa, 0xaa, 0x00, FG.YELLOW, BG.YELLOW),
            (0x88, 0x88, 0x88, FG.GRAY, BG.GRAY),

            (0x44, 0x44, 0xff, FG.BLUE | FG.INTENSITY, BG.BLUE | BG.INTENSITY),
            (0x44, 0xff, 0x44, FG.GREEN | FG.INTENSITY, BG.GREEN | BG.INTENSITY),
            (0x44, 0xff, 0xff, FG.CYAN | FG.INTENSITY, BG.CYAN | BG.INTENSITY),
            (0xff, 0x44, 0x44, FG.RED | FG.INTENSITY, BG.RED | BG.INTENSITY),
            (0xff, 0x44, 0xff, FG.MAGENTA | FG.INTENSITY, BG.MAGENTA | BG.INTENSITY),
            (0xff, 0xff, 0x44, FG.YELLOW | FG.INTENSITY, BG.YELLOW | BG.INTENSITY),

            (0x44, 0x44, 0x44, FG.BLACK | FG.INTENSITY, BG.BLACK | BG.INTENSITY),
            (0xff, 0xff, 0xff, FG.GRAY | FG.INTENSITY, BG.GRAY | BG.INTENSITY),
        ]
545339
function _generateInterpolatedColor() {
  const randIndicies = _getNextColorPair();
  const fraction = Math.random();
  const interpolatedColor = [];

  for (let i = 0; i < 4; i++) {
    interpolatedColor.push(
      Math.floor(
        fraction * distinctColors[randIndicies[0]][i] +
          (1.0 - fraction) * distinctColors[randIndicies[1]][i]
      )
    );
  }

  return interpolatedColor;
}
1377
def colorHSB(h, s, b):
        
        H, S, B = float(h), float(s/100), float(b/100)
        if S == 0.0:
            return (B, B, B) # achromatic (grey)
        h = H / 60
        i = math.floor(h)
        f = h - i
        v = B
        p = v * (1 - S)
        q = v * (1 - S * f)
        t = v * (1 - S * (1 - f))
        if i == 0:
            return (v, t, b)
        elif i == 1:
            return (q, v, p)
        elif i == 2:
            return (p, v, t)
        elif i == 3:
            return (p, q, v)
        elif i == 4:
            return (t, p, v)
        else: # i == 5 (or i == 6 for the case of H == 360)
            return (v, p, q)
1341048
def to_color(self):
        
        color_data = np.repeat(self.data[:,:,np.newaxis], 3, axis=2)
        return ColorImage(color_data, self._frame)
265421
def _hue2rgb(v1, v2, vH):
    

    while vH < 0: vH += 1
    while vH > 1: vH -= 1

    if 6 * vH < 1: return v1 + (v2 - v1) * 6 * vH
    if 2 * vH < 1: return v2
    if 3 * vH < 2: return v1 + (v2 - v1) * ((2.0 / 3) - vH) * 6

    return v1
309297
function hueshiftColor(col, amount) {
  let colRgba = parseColor(col);
  let colHsla = rgbaToHsla(colRgba.r, colRgba.g, colRgba.b, colRgba.a);
  colRgba = hslaToRgba((hsl[0] + amount) % 1, colHsla[1], colHsla[2],colHsla[3]);
  return RGBobj2string({
    r: colRgba[0],
    g: colRgba[1],
    b: colRgba[2],
    a: colRgba[3]
  });
}
745273
def rgb_to_hsv(r, g, b):
    """"""
    h, s, v = colorsys.rgb_to_hsv(r / 255., g / 255., b / 255.)
    return round2(h * 360), round2(s * 100), round2(v * 100)
103266
def calculate_colors(self, values):
        """"""
        # set domain if it is not set
        _flattenedList = list(flatten(values))
        if not self.is_domain_set:
            self.set_domain(_flattenedList)

        _flattenedColors = range(len(_flattenedList))
        for count, value in enumerate(_flattenedList):
            _flattenedColors[count] = self.calculate_color(value)

        return unflatten(values, iter(_flattenedColors))
80071
private static Collection<TileRef> getTiles(Map<ColorRgba, Collection<TileRef>> colors, ColorRgba color)
    {
        if (!colors.containsKey(color))
        {
            colors.put(color, new HashSet<TileRef>());
        }
        return colors.get(color);
    }
887992
def to_hsv
      red, green, blue = *[r, g, b].collect {|x| x / 255.0}
      max = [red, green, blue].max
      min = [red, green, blue].min

      if min == max
        hue = 0
      elsif max == red
        hue = 60 * ((green - blue) / (max - min))
      elsif max == green
        hue = 60 * ((blue - red) / (max - min)) + 120
      elsif max == blue
        hue = 60 * ((red - green) / (max - min)) + 240
      end

      saturation = (max == 0) ? 0 : (max - min) / max
      [hue % 360, saturation, max]
    end
669708
def parallel_plot(df, color=None, palette=None):
    
    npts = df.shape[0]
    ndims = len(df.columns)

    if color is None:
        color = np.ones(npts)
    if palette is None:
        palette = ['#ff0000']

    cmap = LinearColorMapper(high=color.min(),
                             low=color.max(),
                             palette=palette)

    data_source = ColumnDataSource(dict(
        xs=np.arange(ndims)[None, :].repeat(npts, axis=0).tolist(),
        ys=np.array((df-df.min())/(df.max()-df.min())).tolist(),
        color=color))

    p = figure(x_range=(-1, ndims),
               y_range=(0, 1),
               width=1000,
               tools="pan, box_zoom")

    # Create x axis ticks from columns contained in dataframe
    fixed_x_ticks = FixedTicker(
        ticks=np.arange(ndims), minor_ticks=[])
    formatter_x_ticks = FuncTickFormatter(
        code="return columns[index]", args={"columns": df.columns})
    p.xaxis.ticker = fixed_x_ticks
    p.xaxis.formatter = formatter_x_ticks

    p.yaxis.visible = False
    p.y_range.start = 0
    p.y_range.end = 1
    p.y_range.bounds = (-0.1, 1.1) # add a little padding around y axis
    p.xgrid.visible = False
    p.ygrid.visible = False

    # Create extra y axis for each dataframe column
    tickformatter = BasicTickFormatter(precision=1)
    for index, col in enumerate(df.columns):
        start = df[col].min()
        end = df[col].max()
        bound_min = start + abs(end-start) * (p.y_range.bounds[0] - p.y_range.start)
        bound_max = end + abs(end-start) * (p.y_range.bounds[1] - p.y_range.end)
        p.extra_y_ranges.update(
            {col: Range1d(start=bound_min, end=bound_max, bounds=(bound_min, bound_max))})

        fixedticks = FixedTicker(
            ticks=np.linspace(start, end, 8), minor_ticks=[])

        p.add_layout(LinearAxis(fixed_location=index, y_range_name=col,
                                ticker=fixedticks, formatter=tickformatter), 'right')

    # create the data renderer ( MultiLine )
    # specify selected and non selected style
    non_selected_line_style = dict(line_color='grey', line_width=0.1, line_alpha=0.5)

    selected_line_style = dict(line_color={'field': 'color', 'transform': cmap}, line_width=1)

    parallel_renderer = p.multi_line(
        xs="xs", ys="ys", source=data_source, **non_selected_line_style)

    # Specify selection style
    selected_lines = MultiLine(**selected_line_style)

    # Specify non selection style
    nonselected_lines = MultiLine(**non_selected_line_style)

    parallel_renderer.selection_glyph = selected_lines
    parallel_renderer.nonselection_glyph = nonselected_lines
    p.y_range.start = p.y_range.bounds[0]
    p.y_range.end = p.y_range.bounds[1]

    rect_source = ColumnDataSource({
        'x': [], 'y': [], 'width': [], 'height': []
    })

    # add rectangle selections
    selection_renderer = p.rect(x='x', y='y', width='width', height='height',
                                source=rect_source,
                                fill_alpha=0.7, fill_color='#009933')
    selection_tool = ParallelSelectionTool(
        renderer_select=selection_renderer, renderer_data=parallel_renderer,
        box_width=10)
    # custom resets (reset only axes not selections)
    reset_axes = ParallelResetTool()

    # add tools and activate selection ones
    p.add_tools(selection_tool, reset_axes)
    p.toolbar.active_drag = selection_tool
    return p