当前位置: 首页>>代码示例>>Python>>正文


Python colors.rgb2hex方法代码示例

本文整理汇总了Python中matplotlib.colors.rgb2hex方法的典型用法代码示例。如果您正苦于以下问题:Python colors.rgb2hex方法的具体用法?Python colors.rgb2hex怎么用?Python colors.rgb2hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.colors的用法示例。


在下文中一共展示了colors.rgb2hex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _to_hex

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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)) 
开发者ID:atmtools,项目名称:typhon,代码行数:20,代码来源:common.py

示例2: list_of_hex_colours

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:19,代码来源:colours.py

示例3: contourf_to_geojson_overlap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
def contourf_to_geojson_overlap(contourf, geojson_filepath=None, min_angle_deg=None,
                                ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
                                geojson_properties=None, strdump=False, serialize=True):
    """Transform matplotlib.contourf to geojson with overlapping filled contours."""
    polygon_features = []
    contourf_idx = 0
    contourf_levels = get_contourf_levels(contourf.levels, contourf.extend)
    for collection in contourf.collections:
        color = collection.get_facecolor()
        for path in collection.get_paths():
            for coord in path.to_polygons():
                if min_angle_deg:
                    coord = keep_high_angle(coord, min_angle_deg)
                coord = np.around(coord, ndigits) if ndigits else coord
                polygon = Polygon(coordinates=[coord.tolist()])
                fcolor = rgb2hex(color[0])
                properties = set_contourf_properties(stroke_width, fcolor, fill_opacity, contourf_levels[contourf_idx], unit)
                if geojson_properties:
                    properties.update(geojson_properties)
                feature = Feature(geometry=polygon, properties=properties)
                polygon_features.append(feature)
        contourf_idx += 1
    feature_collection = FeatureCollection(polygon_features)
    return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize) 
开发者ID:bartromgens,项目名称:geojsoncontour,代码行数:26,代码来源:contour.py

示例4: scatter_group

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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 
开发者ID:theislab,项目名称:scanpy,代码行数:27,代码来源:_utils.py

示例5: generateColourDict

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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 
开发者ID:DRL,项目名称:blobtools,代码行数:21,代码来源:BtPlot.py

示例6: scatter_plot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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
##################### 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:27,代码来源:farfield.py

示例7: dismph_colormap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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 
开发者ID:bakerunavco,项目名称:pygmtsar,代码行数:26,代码来源:showintf.py

示例8: contour_to_geojson

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
def contour_to_geojson(contour, geojson_filepath=None, min_angle_deg=None,
                       ndigits=5, unit='', stroke_width=1, geojson_properties=None, strdump=False,
                       serialize=True):
    """Transform matplotlib.contour to geojson."""
    collections = contour.collections
    contour_index = 0
    line_features = []
    for collection in collections:
        color = collection.get_edgecolor()
        for path in collection.get_paths():
            v = path.vertices
            if len(v) < 3:
                continue
            coordinates = keep_high_angle(v, min_angle_deg) if min_angle_deg else v
            coordinates = np.around(coordinates, ndigits) if ndigits is not None else coordinates
            line = LineString(coordinates.tolist())
            properties = {
                "stroke-width": stroke_width,
                "stroke": rgb2hex(color[0]),
                "title": "%.2f" % contour.levels[contour_index] + ' ' + unit,
                "level-value": float("%.6f" % contour.levels[contour_index]),
                "level-index": contour_index
            }
            if geojson_properties:
                properties.update(geojson_properties)
            line_features.append(Feature(geometry=line, properties=properties))
        contour_index += 1
    feature_collection = FeatureCollection(line_features)
    return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize) 
开发者ID:bartromgens,项目名称:geojsoncontour,代码行数:31,代码来源:contour.py

示例9: contourf_to_geojson

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
def contourf_to_geojson(contourf, geojson_filepath=None, min_angle_deg=None,
                        ndigits=5, unit='', stroke_width=1, fill_opacity=.9, fill_opacity_range=None,
                        geojson_properties=None, strdump=False, serialize=True):
    """Transform matplotlib.contourf to geojson with MultiPolygons."""
    if fill_opacity_range:
        variable_opacity = True
        min_opacity, max_opacity = fill_opacity_range
        opacity_increment = (max_opacity - min_opacity) / len(contourf.levels)
        fill_opacity = min_opacity
    else:
        variable_opacity = False
    polygon_features = []
    contourf_levels = get_contourf_levels(contourf.levels, contourf.extend)
    for coll, level in zip(contourf.collections, contourf_levels):
        color = coll.get_facecolor()
        muli = MP(coll, min_angle_deg, ndigits)
        polygon = muli.mpoly()
        fcolor = rgb2hex(color[0])
        properties = set_contourf_properties(stroke_width, fcolor, fill_opacity, level, unit)
        if geojson_properties:
            properties.update(geojson_properties)
        feature = Feature(geometry=polygon, properties=properties)
        polygon_features.append(feature)
        if variable_opacity:
            fill_opacity += opacity_increment
    feature_collection = FeatureCollection(polygon_features)
    return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize) 
开发者ID:bartromgens,项目名称:geojsoncontour,代码行数:29,代码来源:contour.py

示例10: _background_gradient

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:15,代码来源:style.py

示例11: convert_colormap_to_hex

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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 
开发者ID:webermarcolivier,项目名称:xlsxpandasformatter,代码行数:15,代码来源:xlsxpandasformatter.py

示例12: col2hex

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
def col2hex(color):
    """Convert matplotlib color to hex before passing to Qt"""
    return rgb2hex(colorConverter.to_rgb(color)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:formlayout.py

示例13: _write_hatches

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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') 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:39,代码来源:backend_svg.py

示例14: random_colorizer

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
def random_colorizer(profile, *args, **kwargs):
    return mcolors.rgb2hex(np.random.rand(3)) 
开发者ID:mobiusklein,项目名称:ms_deisotope,代码行数:4,代码来源:map_viz.py

示例15: _write_hatches

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import rgb2hex [as 别名]
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') 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:42,代码来源:backend_svg.py


注:本文中的matplotlib.colors.rgb2hex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。