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


Python colors.to_rgba方法代码示例

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


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

示例1: test_fillbetween_cycle

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def test_fillbetween_cycle():
    fig, ax = plt.subplots()

    for j in range(3):
        cc = ax.fill_between(range(3), range(3))
        target = mcolors.to_rgba('C{}'.format(j))
        assert tuple(cc.get_facecolors().squeeze()) == tuple(target)

    for j in range(3, 6):
        cc = ax.fill_betweenx(range(3), range(3))
        target = mcolors.to_rgba('C{}'.format(j))
        assert tuple(cc.get_facecolors().squeeze()) == tuple(target)

    target = mcolors.to_rgba('k')

    for al in ['facecolor', 'facecolors', 'color']:
        cc = ax.fill_between(range(3), range(3), **{al: 'k'})
        assert tuple(cc.get_facecolors().squeeze()) == tuple(target)

    edge_target = mcolors.to_rgba('k')
    for j, el in enumerate(['edgecolor', 'edgecolors'], start=6):
        cc = ax.fill_between(range(3), range(3), **{el: 'k'})
        face_target = mcolors.to_rgba('C{}'.format(j))
        assert tuple(cc.get_facecolors().squeeze()) == tuple(face_target)
        assert tuple(cc.get_edgecolors().squeeze()) == tuple(edge_target) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:27,代码来源:test_axes.py

示例2: test_conversions

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def test_conversions():
    # to_rgba_array("none") returns a (0, 4) array.
    assert_array_equal(mcolors.to_rgba_array("none"), np.zeros((0, 4)))
    # a list of grayscale levels, not a single color.
    assert_array_equal(
        mcolors.to_rgba_array([".2", ".5", ".8"]),
        np.vstack([mcolors.to_rgba(c) for c in [".2", ".5", ".8"]]))
    # alpha is properly set.
    assert mcolors.to_rgba((1, 1, 1), .5) == (1, 1, 1, .5)
    assert mcolors.to_rgba(".1", .5) == (.1, .1, .1, .5)
    # builtin round differs between py2 and py3.
    assert mcolors.to_hex((.7, .7, .7)) == "#b2b2b2"
    # hex roundtrip.
    hex_color = "#1234abcd"
    assert mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True) == \
        hex_color 
开发者ID:holzschu,项目名称:python3_ios,代码行数:18,代码来源:test_colors.py

示例3: gethue

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def gethue(color):
    """Get the hue of a color"""
    if isinstance(color, float):
        return color

    if is_color_like(color):
        RGB = to_rgba(color)[:3]
    else:
        raise ValueError("color is not color like")

    Jp, ap, bp = transform(np.array([RGB]))[0]
    hp = np.arctan2(bp, ap) * 180 / np.pi
    print("Decode color \"{}\"; h' = {}".format(color, hp))
    return hp 
开发者ID:liamedeiros,项目名称:ehtplot,代码行数:16,代码来源:cmap.py

示例4: write_png

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def write_png(self, fname):
        """Write the image to png file with fname"""
        from matplotlib import _png
        im = self.to_rgba(self._A[::-1] if self.origin == 'lower' else self._A,
                          bytes=True, norm=True)
        _png.write_png(im, fname) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:8,代码来源:image.py

示例5: make_image

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def make_image(self, renderer, magnification=1.0, unsampled=False):
        # docstring inherited
        if self._A is None:
            raise RuntimeError('You must first set the image array')
        if unsampled:
            raise ValueError('unsampled not supported on NonUniformImage')
        A = self._A
        if A.ndim == 2:
            if A.dtype != np.uint8:
                A = self.to_rgba(A, bytes=True)
                self.is_grayscale = self.cmap.is_gray()
            else:
                A = np.repeat(A[:, :, np.newaxis], 4, 2)
                A[:, :, 3] = 255
                self.is_grayscale = True
        else:
            if A.dtype != np.uint8:
                A = (255*A).astype(np.uint8)
            if A.shape[2] == 3:
                B = np.zeros(tuple([*A.shape[0:2], 4]), np.uint8)
                B[:, :, 0:3] = A
                B[:, :, 3] = 255
                A = B
            self.is_grayscale = False
        x0, y0, v_width, v_height = self.axes.viewLim.bounds
        l, b, r, t = self.axes.bbox.extents
        width = (np.round(r) + 0.5) - (np.round(l) - 0.5)
        height = (np.round(t) + 0.5) - (np.round(b) - 0.5)
        width *= magnification
        height *= magnification
        im = _image.pcolor(self._Ax, self._Ay, A,
                           int(height), int(width),
                           (x0, x0+v_width, y0, y0+v_height),
                           _interpd_[self._interpolation])
        return im, l, b, IdentityTransform() 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:37,代码来源:image.py

示例6: to_qcolor

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def to_qcolor(color):
    """Create a QColor from a matplotlib color"""
    qcolor = QtGui.QColor()
    try:
        rgba = mcolors.to_rgba(color)
    except ValueError:
        cbook._warn_external('Ignoring invalid color %r' % color)
        return qcolor  # return invalid QColor
    qcolor.setRgbF(*rgba)
    return qcolor 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:12,代码来源:_formlayout.py

示例7: write_png

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def write_png(self, fname):
        """Write the image to png file with fname"""
        im = self.to_rgba(self._A[::-1] if self.origin == 'lower' else self._A,
                          bytes=True, norm=True)
        _png.write_png(im, fname) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:image.py

示例8: make_image

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def make_image(self, renderer, magnification=1.0, unsampled=False):
        if self._A is None:
            raise RuntimeError('You must first set the image array')

        if unsampled:
            raise ValueError('unsampled not supported on NonUniformImage')

        A = self._A
        if A.ndim == 2:
            if A.dtype != np.uint8:
                A = self.to_rgba(A, bytes=True)
                self.is_grayscale = self.cmap.is_gray()
            else:
                A = np.repeat(A[:, :, np.newaxis], 4, 2)
                A[:, :, 3] = 255
                self.is_grayscale = True
        else:
            if A.dtype != np.uint8:
                A = (255*A).astype(np.uint8)
            if A.shape[2] == 3:
                B = np.zeros(tuple([*A.shape[0:2], 4]), np.uint8)
                B[:, :, 0:3] = A
                B[:, :, 3] = 255
                A = B
            self.is_grayscale = False

        x0, y0, v_width, v_height = self.axes.viewLim.bounds
        l, b, r, t = self.axes.bbox.extents
        width = (np.round(r) + 0.5) - (np.round(l) - 0.5)
        height = (np.round(t) + 0.5) - (np.round(b) - 0.5)
        width *= magnification
        height *= magnification
        im = _image.pcolor(self._Ax, self._Ay, A,
                           int(height), int(width),
                           (x0, x0+v_width, y0, y0+v_height),
                           _interpd_[self._interpolation])

        return im, l, b, IdentityTransform() 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:40,代码来源:image.py

示例9: to_qcolor

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def to_qcolor(color):
    """Create a QColor from a matplotlib color"""
    qcolor = QtGui.QColor()
    try:
        rgba = mcolors.to_rgba(color)
    except ValueError:
        warnings.warn('Ignoring invalid color %r' % color, stacklevel=2)
        return qcolor  # return invalid QColor
    qcolor.setRgbF(*rgba)
    return qcolor 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:12,代码来源:formlayout.py

示例10: to_png

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):
        """
        Writes a tex expression to a PNG file.

        Returns the offset of the baseline from the bottom of the
        image in pixels.

        *filename*
            A writable filename or fileobject

        *texstr*
            A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'

        *color*
            A valid matplotlib color argument

        *dpi*
            The dots-per-inch to render the text

        *fontsize*
            The font size in points

        Returns the offset of the baseline from the bottom of the
        image in pixels.
        """
        rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize)
        _png.write_png(rgba, filename)
        return depth 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:30,代码来源:mathtext.py

示例11: __init__

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def __init__(self, offset=(2, -2),
                 shadow_rgbFace=None, alpha=None,
                 rho=0.3, **kwargs):
        """
        Parameters
        ----------
        offset : pair of floats
            The offset of the shadow in points.
        shadow_rgbFace : color
            The shadow color.
        alpha : float
            The alpha transparency of the created shadow patch.
            Default is 0.3.
            http://matplotlib.1069221.n5.nabble.com/path-effects-question-td27630.html
        rho : float
            A scale factor to apply to the rgbFace color if `shadow_rgbFace`
            is not specified. Default is 0.3.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.

        """
        super().__init__(offset)

        if shadow_rgbFace is None:
            self._shadow_rgbFace = shadow_rgbFace
        else:
            self._shadow_rgbFace = mcolors.to_rgba(shadow_rgbFace)

        if alpha is None:
            alpha = 0.3

        self._alpha = alpha
        self._rho = rho

        #: The dictionary of keywords to update the graphics collection with.
        self._gc = kwargs

        #: The offset transform object. The offset isn't calculated yet
        #: as we don't know how big the figure will be in pixels.
        self._offset_tran = mtransforms.Affine2D() 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:43,代码来源:patheffects.py

示例12: __init__

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def __init__(self, color):
        rgb = mcolors.to_rgba(color)[:3]
        self.im = np.dstack(
            [self.b_and_h - self.color * (1 - np.array(rgb)), self.alpha]) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:6,代码来源:demo_ribbon_box.py

示例13: __init__

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def __init__(self, fontsize=14, labelcolor='black', bgcolor='yellow',
                 alpha=1.0):
        self.fontsize = fontsize
        self.labelcolor = labelcolor
        self.bgcolor = bgcolor
        self.alpha = alpha

        self.labelcolor_rgb = colors.to_rgba(labelcolor)[:3]
        self.bgcolor_rgb = colors.to_rgba(bgcolor)[:3] 
开发者ID:holzschu,项目名称:python3_ios,代码行数:11,代码来源:menu.py

示例14: cc

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def cc(arg):
    '''
    Shorthand to convert 'named' colors to rgba format at 60% opacity.
    '''
    return mcolors.to_rgba(arg, alpha=0.6) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:7,代码来源:polys3d.py

示例15: to_rgba

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import to_rgba [as 别名]
def to_rgba(self, texstr, color='black', dpi=120, fontsize=14):
        """
        *texstr*
            A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'

        *color*
            Any matplotlib color argument

        *dpi*
            The dots-per-inch to render the text

        *fontsize*
            The font size in points

        Returns a tuple (*array*, *depth*)

          - *array* is an NxM uint8 alpha ubyte mask array of
            rasterized tex.

          - depth is the offset of the baseline from the bottom of the
            image in pixels.
        """
        x, depth = self.to_mask(texstr, dpi=dpi, fontsize=fontsize)

        r, g, b, a = mcolors.to_rgba(color)
        RGBA = np.zeros((x.shape[0], x.shape[1], 4), dtype=np.uint8)
        RGBA[:, :, 0] = 255 * r
        RGBA[:, :, 1] = 255 * g
        RGBA[:, :, 2] = 255 * b
        RGBA[:, :, 3] = x
        return RGBA, depth 
开发者ID:holzschu,项目名称:python3_ios,代码行数:33,代码来源:mathtext.py


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