def _create_random_colormap(self, values, low=0, high=255): """ Generate colormap and colorbar with random discrete colors Parameters ---------- values : list or 1D array values for which the random colors are to be generated Returns ------- cmap : matplotlib.color.Colormap norm : matplotlib.color.BoundaryNorm """ # create first random color randomColors = [get_random_color(low=low, high=high)] # add more random colors for v in values[1:]: randomColors.append( get_random_color(randomColors[-1], low=low, high=high)) # create colormap and norm cmap = mpl.colors.ListedColormap(randomColors) bounds = sorted(list(values)) bounds += [max(bounds) + 1] # bounds should be longer than values by 1 norm = mpl.colors.BoundaryNorm(bounds, cmap.N) return cmap, norm
def _create_random_colormap(self, values, low=0, high=255): ''' Generate colormap and colorbar with random discrete colors Parameters ---------- values : list or 1D array values for which the random colors are to be generated Returns ------- cmap : matplotlib.color.Colormap norm : matplotlib.color.BoundaryNorm ''' # create first random color randomColors = [get_random_color(low=low, high=high)] # add more random colors for v in values[1:]: randomColors.append(get_random_color(randomColors[-1], low=low, high=high)) # create colormap and norm cmap = mpl.colors.ListedColormap(randomColors) bounds = sorted(list(values)) bounds += [max(bounds) + 1] # bounds should be longer than values by 1 norm = mpl.colors.BoundaryNorm(bounds, cmap.N) return cmap, norm
def test_get_random_color(self): ''' Should return HEX code of random color ''' c0 = get_random_color() c1 = get_random_color(c0) c2 = get_random_color(c1, 300) self.assertEqual(type(hex2color(c0)), tuple) self.assertEqual(type(hex2color(c1)), tuple) self.assertEqual(type(hex2color(c2)), tuple)
def test_get_random_color__matplotlib_missing(self): with self.assertRaises(ImportError): c0 = get_random_color()