Python matplotlib.colors.rgb2hex() Examples
The following are 30
code examples of matplotlib.colors.rgb2hex().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.colors
, or try the search function
.
Example #1
Source File: common.py From typhon with MIT License | 6 votes |
def _to_hex(c): """Convert arbitray color specification to hex string.""" ctype = type(c) # Convert rgb to hex. if ctype is tuple or ctype is np.ndarray or ctype is list: return colors.rgb2hex(c) if ctype is str: # If color is already hex, simply return it. regex = re.compile('^#[A-Fa-f0-9]{6}$') if regex.match(c): return c # Convert named color to hex. return colors.cnames[c] raise Exception("Can't handle color of type: {}".format(ctype))
Example #2
Source File: colours.py From LSDMappingTools with MIT License | 6 votes |
def list_of_hex_colours(N, base_cmap): """ Return a list of colors from a colourmap as hex codes Arguments: cmap: colormap instance, eg. cm.jet. N: number of colors. Author: FJC """ cmap = _cm.get_cmap(base_cmap, N) hex_codes = [] for i in range(cmap.N): rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb hex_codes.append(_mcolors.rgb2hex(rgb)) return hex_codes
Example #3
Source File: xlsxpandasformatter.py From xlsxpandasformatter with MIT License | 6 votes |
def convert_colormap_to_hex(cmap, x, vmin=0, vmax=1): """ Example:: >>> seaborn.palplot(seaborn.color_palette("RdBu_r", 7)) >>> colorMapRGB = seaborn.color_palette("RdBu_r", 61) >>> colormap = seaborn.blend_palette(colorMapRGB, as_cmap=True, input='rgb') >>> [convert_colormap_to_hex(colormap, x, vmin=-2, vmax=2) for x in range(-2, 3)] ['#09386d', '#72b1d3', '#f7f6f5', '#e7866a', '#730421'] """ norm = colors.Normalize(vmin, vmax) color_rgb = plt.cm.get_cmap(cmap)(norm(x)) color_hex = colors.rgb2hex(color_rgb) return color_hex
Example #4
Source File: BtPlot.py From blobtools with GNU General Public License v3.0 | 6 votes |
def generateColourDict(colour_groups, groups): cmap = [rgb2hex(rgb) for rgb in cm.get_cmap(name=COLOURMAP).colors] # remove green del cmap[2] # remove brown del cmap[4] colour_d = {} idx_delay = 0 for idx, group in enumerate(groups): if group in colour_groups: #print(group,) if group == 'no-hit' or group == 'None': colour_d[group] = GREY #print("GREY") idx_delay -= 1 else: colour_d[group] = cmap[idx+idx_delay] #print(colour_d[group], idx+idx_delay) return colour_d
Example #5
Source File: showintf.py From pygmtsar with MIT License | 6 votes |
def dismph_colormap(): '''Make a custom colormap like the one used in dismph. The list was created from dismphN.mat in geodmod which is a 64 segmented colormap using the following: from scipy.io import loadmat cmap = loadmat('dismphN.mat',struct_as_record=True)['dismphN'] from matplotlib.colors import rgb2hex list=[] for i in cmap: list.append(rgb2hex(i)) ''' list = ['#f579cd', '#f67fc6', '#f686bf', '#f68cb9', '#f692b3', '#f698ad', '#f69ea7', '#f6a5a1', '#f6ab9a', '#f6b194', '#f6b78e', '#f6bd88', '#f6c482', '#f6ca7b', '#f6d075', '#f6d66f', '#f6dc69', '#f6e363', '#efe765', '#e5eb6b', '#dbf071', '#d0f477', '#c8f67d', '#c2f684', '#bbf68a', '#b5f690', '#aff696', '#a9f69c', '#a3f6a3', '#9cf6a9', '#96f6af', '#90f6b5', '#8af6bb', '#84f6c2', '#7df6c8', '#77f6ce', '#71f6d4', '#6bf6da', '#65f6e0', '#5ef6e7', '#58f0ed', '#52e8f3', '#4cdbf9', '#7bccf6', '#82c4f6', '#88bdf6', '#8eb7f6', '#94b1f6', '#9aabf6', '#a1a5f6', '#a79ef6', '#ad98f6', '#b392f6', '#b98cf6', '#bf86f6', '#c67ff6', '#cc79f6', '#d273f6', '#d86df6', '#de67f6', '#e561f6', '#e967ec', '#ed6de2', '#f173d7'] dismphCM = matplotlib.colors.LinearSegmentedColormap.from_list('mycm', list) dismphCM.set_bad('w', 0.0) return dismphCM
Example #6
Source File: _utils.py From scanpy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def scatter_group(ax, key, imask, adata, Y, projection='2d', size=3, alpha=None): """Scatter of group using representation of data Y. """ mask = adata.obs[key].cat.categories[imask] == adata.obs[key].values color = adata.uns[key + '_colors'][imask] if not isinstance(color[0], str): from matplotlib.colors import rgb2hex color = rgb2hex(adata.uns[key + '_colors'][imask]) if not is_color_like(color): raise ValueError('"{}" is not a valid matplotlib color.'.format(color)) data = [Y[mask, 0], Y[mask, 1]] if projection == '3d': data.append(Y[mask, 2]) ax.scatter( *data, marker='.', alpha=alpha, c=color, edgecolors='none', s=size, label=adata.obs[key].cat.categories[imask], rasterized=settings._vector_friendly, ) return mask
Example #7
Source File: farfield.py From spins-b with GNU General Public License v3.0 | 6 votes |
def scatter_plot(ax, points: np.array, triangles: np.array, E2: np.array): ''' plots scatter data Note: The axis has to be made with mpl_toolkits.mplot3d.Axes3D ''' # get the maximum value of E2 r_max = np.max(E2) for i in range(triangles.shape[0]): vtx = np.vstack([ E2[int(triangles[i, 0])] * points[int(triangles[i, 0])], E2[int(triangles[i, 1])] * points[int(triangles[i, 1])], E2[int(triangles[i, 2])] * points[int(triangles[i, 2])] ]) r = np.sum((np.sum(vtx, axis=0) / 3)**2)**0.5 tri = a3.art3d.Poly3DCollection([vtx]) tri.set_color(colors.rgb2hex(get_jet_colors(r / r_max))) tri.set_edgecolor('k') ax.add_collection3d(tri) ax.set_xlim(-r_max, r_max) ax.set_ylim(-r_max, r_max) ax.set_zlim(-r_max, r_max) # Analysis functions #####################
Example #8
Source File: layer_properties.py From innstereo with GNU General Public License v2.0 | 5 votes |
def on_colorbutton_choose_line_color_color_set(self, color_button): """ Triggered when the line color is changed. The function receives a Gtk.ColorButton instance. Queues up the new line color in the list of changes. """ rgba = color_button.get_rgba() rgb_str = rgba.to_string() red, green, blue = rgb_str[4:-1].split(",") color_list = [int(red)/255, int(green)/255, int(blue)/255] new_line_color_hex = colors.rgb2hex(color_list) self.changes.append(lambda: self.layer.set_line_color( new_line_color_hex))
Example #9
Source File: dialog_windows.py From innstereo with GNU General Public License v2.0 | 5 votes |
def on_colorbutton_canvas_color_set(self, colorbutton): # pylint: disable=unused-argument """ Queues up the new color of the canvas. Triggered when a new color is chosen for the canvas. """ rgba = colorbutton.get_rgba() rgb_str = rgba.to_string() red, green, blue = rgb_str[4:-1].split(",") color_list = [int(red)/255, int(green)/255, int(blue)/255] new_canvas_color = colors.rgb2hex(color_list) self.changes.append( lambda: self.settings.set_canvas_color(new_canvas_color))
Example #10
Source File: layer_properties.py From innstereo with GNU General Public License v2.0 | 5 votes |
def on_colorbutton_pole_fill_color_set(self, colorbutton): """ Queues up the new pole fill color in the list of changes. """ rgba = colorbutton.get_rgba() rgb_str = rgba.to_string() red, green, blue = rgb_str[4:-1].split(",") color_list = [int(red)/255, int(green)/255, int(blue)/255] new_pole_color_hex = colors.rgb2hex(color_list) self.changes.append(lambda: self.layer.set_pole_fill( new_pole_color_hex))
Example #11
Source File: layer_properties.py From innstereo with GNU General Public License v2.0 | 5 votes |
def on_colorbutton_pole_edge_color_color_set(self, colorbutton): """ Queues up the new pole edge color in the list of changes. """ rgba = colorbutton.get_rgba() rgb_str = rgba.to_string() red, green, blue = rgb_str[4:-1].split(",") color_list = [int(red)/255, int(green)/255, int(blue)/255] new_pole_edge_color_hex = colors.rgb2hex(color_list) self.changes.append(lambda: self.layer.set_pole_edge_color( new_pole_edge_color_hex))
Example #12
Source File: layer_properties.py From innstereo with GNU General Public License v2.0 | 5 votes |
def on_colorbutton_marker_color_set(self, color_button): """ Queues up the new marker fill color in the list of changes. """ rgba = color_button.get_rgba() rgb_str = rgba.to_string() red, green, blue = rgb_str[4:-1].split(",") color_list = [int(red)/255, int(green)/255, int(blue)/255] new_marker_color_hex = colors.rgb2hex(color_list) self.changes.append(lambda: self.layer.set_marker_fill( new_marker_color_hex))
Example #13
Source File: layer_properties.py From innstereo with GNU General Public License v2.0 | 5 votes |
def on_colorbutton_contour_line_color_color_set(self, colorbutton): """ Queues up the new contour line color in the list of changes. """ rgba = colorbutton.get_rgba() rgb_str = rgba.to_string() red, green, blue = rgb_str[4:-1].split(",") color_list = [int(red)/255, int(green)/255, int(blue)/255] new_color = colors.rgb2hex(color_list) self.changes.append( lambda: self.layer.set_contour_line_color(new_color))
Example #14
Source File: colors.py From ChainConsumer with MIT License | 5 votes |
def format(self, color): if isinstance(color, np.ndarray): color = rgb2hex(color) if color[0] == "#": return color elif color in self.color_map: return self.color_map[color] elif color in self.aliases: alias = self.aliases[color] return self.color_map[alias] else: raise ValueError("Color %s is not mapped. Please give a hex code" % color)
Example #15
Source File: formlayout.py From ImageFusion with MIT License | 5 votes |
def col2hex(color): """Convert matplotlib color to hex before passing to Qt""" return rgb2hex(colorConverter.to_rgb(color))
Example #16
Source File: formlayout.py From ImageFusion with MIT License | 5 votes |
def col2hex(color): """Convert matplotlib color to hex before passing to Qt""" return rgb2hex(colorConverter.to_rgb(color))
Example #17
Source File: backend_svg.py From ImageFusion with MIT License | 5 votes |
def _write_hatches(self): if not len(self._hatchd): return HATCH_SIZE = 72 writer = self.writer writer.start('defs') for ((path, face, stroke), oid) in six.itervalues(self._hatchd): writer.start( 'pattern', id=oid, patternUnits="userSpaceOnUse", x="0", y="0", width=six.text_type(HATCH_SIZE), height=six.text_type(HATCH_SIZE)) path_data = self._convert_path( path, Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE), simplify=False) if face is None: fill = 'none' else: fill = rgb2hex(face) writer.element( 'rect', x="0", y="0", width=six.text_type(HATCH_SIZE+1), height=six.text_type(HATCH_SIZE+1), fill=fill) writer.element( 'path', d=path_data, style=generate_css({ 'fill': rgb2hex(stroke), 'stroke': rgb2hex(stroke), 'stroke-width': '1.0', 'stroke-linecap': 'butt', 'stroke-linejoin': 'miter' }) ) writer.end('pattern') writer.end('defs')
Example #18
Source File: style.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _background_gradient(s, cmap='PuBu', low=0, high=0): """Color background in a range according to the data.""" with _mpl(Styler.background_gradient) as (plt, colors): rng = s.max() - s.min() # extend lower / upper bounds, compresses color range norm = colors.Normalize(s.min() - (rng * low), s.max() + (rng * high)) # matplotlib modifies inplace? # https://github.com/matplotlib/matplotlib/issues/5427 normed = norm(s.values) c = [colors.rgb2hex(x) for x in plt.cm.get_cmap(cmap)(normed)] return ['background-color: {color}'.format(color=color) for color in c]
Example #19
Source File: table.py From tia with BSD 3-Clause "New" or "Revised" License | 5 votes |
def heat_map(self, cmap='RdYlGn', vmin=None, vmax=None, font_cmap=None): if cmap is None: carr = ['#d7191c', '#fdae61', '#ffffff', '#a6d96a', '#1a9641'] cmap = LinearSegmentedColormap.from_list('default-heatmap', carr) if isinstance(cmap, basestring): cmap = get_cmap(cmap) if isinstance(font_cmap, basestring): font_cmap = get_cmap(font_cmap) vals = self.actual_values.astype(float) if vmin is None: vmin = vals.min().min() if vmax is None: vmax = vals.max().max() norm = (vals - vmin) / (vmax - vmin) for ridx in range(self.nrows): for cidx in range(self.ncols): v = norm.iloc[ridx, cidx] if np.isnan(v): continue color = cmap(v) hex = rgb2hex(color) styles = {'BACKGROUND': HexColor(hex)} if font_cmap is not None: styles['TEXTCOLOR'] = HexColor(rgb2hex(font_cmap(v))) self.iloc[ridx, cidx].apply_styles(styles) return self
Example #20
Source File: style.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _background_gradient(s, cmap='PuBu', low=0, high=0): """Color background in a range according to the data.""" with _mpl(Styler.background_gradient) as (plt, colors): rng = s.max() - s.min() # extend lower / upper bounds, compresses color range norm = colors.Normalize(s.min() - (rng * low), s.max() + (rng * high)) # matplotlib modifies inplace? # https://github.com/matplotlib/matplotlib/issues/5427 normed = norm(s.values) c = [colors.rgb2hex(x) for x in plt.cm.get_cmap(cmap)(normed)] return ['background-color: {color}'.format(color=color) for color in c]
Example #21
Source File: plotting.py From astrocats with MIT License | 5 votes |
def radiocolorf(freq): ffreq = (float(freq) - 1.0)/(45.0 - 1.0) pal = sns.diverging_palette(200, 60, l=80, as_cmap=True, center="dark") return rgb2hex(pal(ffreq))
Example #22
Source File: backend_svg.py From coffeegrindsize with MIT License | 5 votes |
def _write_hatches(self): if not len(self._hatchd): return HATCH_SIZE = 72 writer = self.writer writer.start('defs') for (path, face, stroke), oid in self._hatchd.values(): writer.start( 'pattern', id=oid, patternUnits="userSpaceOnUse", x="0", y="0", width=str(HATCH_SIZE), height=str(HATCH_SIZE)) path_data = self._convert_path( path, Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE), simplify=False) if face is None: fill = 'none' else: fill = rgb2hex(face) writer.element( 'rect', x="0", y="0", width=str(HATCH_SIZE+1), height=str(HATCH_SIZE+1), fill=fill) writer.element( 'path', d=path_data, style=generate_css({ 'fill': rgb2hex(stroke), 'stroke': rgb2hex(stroke), 'stroke-width': str(rcParams['hatch.linewidth']), 'stroke-linecap': 'butt', 'stroke-linejoin': 'miter' }) ) writer.end('pattern') writer.end('defs')
Example #23
Source File: backend_svg.py From CogAlg with MIT License | 5 votes |
def _write_hatches(self): if not len(self._hatchd): return HATCH_SIZE = 72 writer = self.writer writer.start('defs') for (path, face, stroke), oid in self._hatchd.values(): writer.start( 'pattern', id=oid, patternUnits="userSpaceOnUse", x="0", y="0", width=str(HATCH_SIZE), height=str(HATCH_SIZE)) path_data = self._convert_path( path, Affine2D() .scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE), simplify=False) if face is None: fill = 'none' else: fill = rgb2hex(face) writer.element( 'rect', x="0", y="0", width=str(HATCH_SIZE+1), height=str(HATCH_SIZE+1), fill=fill) writer.element( 'path', d=path_data, style=generate_css({ 'fill': rgb2hex(stroke), 'stroke': rgb2hex(stroke), 'stroke-width': str(rcParams['hatch.linewidth']), 'stroke-linecap': 'butt', 'stroke-linejoin': 'miter' }) ) writer.end('pattern') writer.end('defs')
Example #24
Source File: color.py From SecuML with GNU General Public License v2.0 | 5 votes |
def colors(num): colors = color_palette(palette='hls', n_colors=num) return list(map(rgb2hex, colors))
Example #25
Source File: backend_svg.py From twitter-stock-recommendation with MIT License | 5 votes |
def _write_hatches(self): if not len(self._hatchd): return HATCH_SIZE = 72 writer = self.writer writer.start('defs') for ((path, face, stroke), oid) in six.itervalues(self._hatchd): writer.start( 'pattern', id=oid, patternUnits="userSpaceOnUse", x="0", y="0", width=six.text_type(HATCH_SIZE), height=six.text_type(HATCH_SIZE)) path_data = self._convert_path( path, Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE), simplify=False) if face is None: fill = 'none' else: fill = rgb2hex(face) writer.element( 'rect', x="0", y="0", width=six.text_type(HATCH_SIZE+1), height=six.text_type(HATCH_SIZE+1), fill=fill) writer.element( 'path', d=path_data, style=generate_css({ 'fill': rgb2hex(stroke), 'stroke': rgb2hex(stroke), 'stroke-width': six.text_type(rcParams['hatch.linewidth']), 'stroke-linecap': 'butt', 'stroke-linejoin': 'miter' }) ) writer.end('pattern') writer.end('defs')
Example #26
Source File: formlayout.py From neural-network-animation with MIT License | 5 votes |
def col2hex(color): """Convert matplotlib color to hex before passing to Qt""" return rgb2hex(colorConverter.to_rgb(color))
Example #27
Source File: backend_svg.py From Computable with MIT License | 5 votes |
def _write_hatches(self): if not len(self._hatchd): return HATCH_SIZE = 72 writer = self.writer writer.start('defs') for ((path, face, stroke), oid) in self._hatchd.values(): writer.start( u'pattern', id=oid, patternUnits=u"userSpaceOnUse", x=u"0", y=u"0", width=unicode(HATCH_SIZE), height=unicode(HATCH_SIZE)) path_data = self._convert_path( path, Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE), simplify=False) if face is None: fill = u'none' else: fill = rgb2hex(face) writer.element( u'rect', x=u"0", y=u"0", width=unicode(HATCH_SIZE+1), height=unicode(HATCH_SIZE+1), fill=fill) writer.element( u'path', d=path_data, style=generate_css({ u'fill': rgb2hex(stroke), u'stroke': rgb2hex(stroke), u'stroke-width': u'1.0', u'stroke-linecap': u'butt', u'stroke-linejoin': u'miter' }) ) writer.end(u'pattern') writer.end(u'defs')
Example #28
Source File: formlayout.py From Computable with MIT License | 5 votes |
def col2hex(color): """Convert matplotlib color to hex before passing to Qt""" return rgb2hex(colorConverter.to_rgb(color))
Example #29
Source File: map_viz.py From ms_deisotope with Apache License 2.0 | 5 votes |
def random_colorizer(profile, *args, **kwargs): return mcolors.rgb2hex(np.random.rand(3))
Example #30
Source File: backend_svg.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def _write_hatches(self): if not len(self._hatchd): return HATCH_SIZE = 72 writer = self.writer writer.start('defs') for (path, face, stroke), oid in self._hatchd.values(): writer.start( 'pattern', id=oid, patternUnits="userSpaceOnUse", x="0", y="0", width=str(HATCH_SIZE), height=str(HATCH_SIZE)) path_data = self._convert_path( path, Affine2D() .scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE), simplify=False) if face is None: fill = 'none' else: fill = rgb2hex(face) writer.element( 'rect', x="0", y="0", width=str(HATCH_SIZE+1), height=str(HATCH_SIZE+1), fill=fill) writer.element( 'path', d=path_data, style=generate_css({ 'fill': rgb2hex(stroke), 'stroke': rgb2hex(stroke), 'stroke-width': str(rcParams['hatch.linewidth']), 'stroke-linecap': 'butt', 'stroke-linejoin': 'miter' }) ) writer.end('pattern') writer.end('defs')