def test_to_color_strings(colors): """Tests for function to_color_strings with different color inputs.""" if len(colors) == 3: expected = ['#0000ff', '#ff0000', '#7f7f7f'] else: expected = ['#ff0000', '#008000', '#000000', '#ffffff'] assert to_color_strings(colors) == expected
def _get_vertexcolor(surf_map, cmap, norm, absolute_threshold=None, bg_map=None): vertexcolor = cmap(norm(surf_map).data) if absolute_threshold is None: return to_color_strings(vertexcolor) if bg_map is None: bg_map = np.ones(len(surf_map)) * .5 bg_vmin, bg_vmax = 0, 1 else: bg_map = surface.load_surf_data(bg_map) bg_vmin, bg_vmax = np.min(bg_map), np.max(bg_map) bg_norm = mpl.colors.Normalize(vmin=bg_vmin, vmax=bg_vmax) bg_color = mpl_cm.get_cmap('Greys')(bg_norm(bg_map)) vertexcolor[np.abs(surf_map) < absolute_threshold] = bg_color[ np.abs(surf_map) < absolute_threshold] return to_color_strings(vertexcolor)
def test_to_color_strings(): colors = [[0, 0, 1], [1, 0, 0], [.5, .5, .5]] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = [[0, 0, 1, 1], [1, 0, 0, 1], [.5, .5, .5, 0]] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = ['#0000ff', '#ff0000', '#7f7f7f'] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = [[0, 0, 1, 1], [1, 0, 0, 1], [.5, .5, .5, 0]] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = ['r', 'green', 'black', 'white'] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#ff0000', '#008000', '#000000', '#ffffff'] if matplotlib.__version__ < '2': return colors = ['#0000ffff', '#ff0000ab', '#7f7f7f00'] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f']
def test_to_color_strings(): colors = [[0, 0, 1], [1, 0, 0], [.5, .5, .5]] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = [[0, 0, 1, 1], [1, 0, 0, 1], [.5, .5, .5, 0]] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = ['#0000ff', '#ff0000', '#7f7f7f'] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = [[0, 0, 1, 1], [1, 0, 0, 1], [.5, .5, .5, 0]] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f'] colors = ['r', 'green', 'black', 'white'] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#ff0000', '#008000', '#000000', '#ffffff'] if matplotlib.__version__ < '2': return colors = ['#0000ffff', '#ff0000ab', '#7f7f7f00'] as_str = js_plotting_utils.to_color_strings(colors) assert as_str == ['#0000ff', '#ff0000', '#7f7f7f']