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


Python ColorConverter.to_rgba方法代码示例

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


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

示例1: __init__

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
 def __init__(self, c1, c2=None, cluster=None):
     c= ColorConverter()
     if c2 is None:
         self.mincol,self.maxcol = c.to_rgba(c1[0]), c.to_rgba(c1[1])
     else:
         self.mincol, self.maxcol = c.to_rgba(c1), c.to_rgba(c2)
     self.cluster = cluster
开发者ID:BenjaminPeter,项目名称:pooGUI,代码行数:9,代码来源:SampleFrame.py

示例2: plot2

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
    def plot2(self):
        """
        plot curves of function integrand for different beta values
        """
        from matplotlib.collections import LineCollection
        from matplotlib.colors import ColorConverter
        colorConverter = ColorConverter()
        
        slab = SlabModel() # R is unimportant
        eta  = linspace(0.0, 1.0, num=100)
        
        fig = P.figure(1)
        P.clf()

        #
        #--- subplot 1: Fixed lambda, varying beta
        ax1 = fig.add_subplot(2,1,1)
        ax1.set_xlim((0.0, 1.0))

        beta = linspace(0.0, 1.0, num=10)
        ym = [ slab.PaulMcSpaddenIntegrand(eta, beta=b, m=3) for b in beta ]
        line_segments =  LineCollection( [ zip(eta,y) for y in ym ],
                                         colors = [colorConverter.to_rgba(i) \
                                                   for i in ('b','g','r','c','m','y','k')]
                                         )
        ax1.add_collection( line_segments, autolim=True )
        ax1.autoscale_view() 
        axhline()
        ax1.set_xlabel(r'$\eta\quad\quad(m=3)$')
        ax1.set_ylabel(r'$\mbox{erf}(\beta\eta)\sin(\lambda_m\eta)$')

        #
        #--- subplot 2: Fixed beta, varying lambda
        ax2 = fig.add_subplot(2,1,2)
        ax2.set_xlim((0.0, 1.0))

        ym = [ slab.PaulMcSpaddenIntegrand(eta, beta=0.27, m=m) for m in range(10) ]
        line_segments =  LineCollection( [ zip(eta,y) for y in ym ],
                                         colors = [colorConverter.to_rgba(i) \
                                                   for i in ('b','g','r','c','m','y','k')]
                                         )
        ax2.add_collection( line_segments, autolim=True )
        ax2.autoscale_view() 
        axhline()
        ax2.set_xlabel(r'$\eta\quad\quad(\beta=0.27)$')
        ax2.set_ylabel(r'$\mbox{erf}(\beta\eta)\sin(\lambda_m\eta)$')

        P.show()
        return
开发者ID:claudioalmeida,项目名称:Artigos,代码行数:51,代码来源:profiles.py

示例3: _set_ax_pathcollection_to_bw

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def _set_ax_pathcollection_to_bw(collection, ax, style, colormap):
    '''helper function for converting a pathcollection to black and white
    
    Parameters
    ----------
    collection : pathcollection
    ax : axes
    style : {GREYSCALE, HATCHING}
    colormap : dict
               mapping of color to B&W rendering
    
    '''
    color_converter = ColorConverter()
    colors = {}
    for key, value in color_converter.colors.items():
        colors[value] = key    

    rgb_orig = collection._facecolors_original
    rgb_orig = [color_converter.to_rgb(row) for row in rgb_orig]
    
    new_color = [color_converter.to_rgba(colormap[entry]['fill']) for entry 
                 in rgb_orig]
    new_color = np.asarray(new_color)
    
    collection.update({'facecolors' : new_color}) 
    collection.update({'edgecolors' : new_color}) 
开发者ID:JamesPHoughton,项目名称:EMAworkbench,代码行数:28,代码来源:b_and_w_plotting.py

示例4: _set_ax_polycollection_to_bw

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def _set_ax_polycollection_to_bw(collection, ax, style):
    '''helper function for converting a polycollection to black and white
    
    Parameters
    ----------
    collection : polycollection
    ax : axes
    style : {GREYSCALE, HATCHING}
    
    '''

    if style==GREYSCALE:

        color_converter = ColorConverter()
        for polycollection in ax.collections:
            rgb_orig = polycollection._facecolors_original
            if rgb_orig in COLORMAP.keys():
                new_color = color_converter.to_rgba(COLORMAP[rgb_orig]['fill'])
                new_color = np.asarray([new_color])
                polycollection.update({'facecolors' : new_color}) 
                polycollection.update({'edgecolors' : new_color})
    elif style==HATCHING:
        rgb_orig = collection._facecolors_original
        collection.update({'facecolors' : 'none'}) 
        collection.update({'edgecolors' : 'white'}) 
        collection.update({'alpha':1})
        
        for path in collection.get_paths():
            p1 = mpl.patches.PathPatch(path, fc="none", 
                                       hatch=COLORMAP[rgb_orig]['hatch'])
            ax.add_patch(p1)
            p1.set_zorder(collection.get_zorder()-0.1)
开发者ID:feilos,项目名称:EMAworkbench,代码行数:34,代码来源:b_and_w_plotting.py

示例5: drawImpacts

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
	def drawImpacts(self):
		# Load the dataset
		dataset = self.datasetManager.loadDataset(self.datasetManager.getAccuracyComplete())
		
		# Create the scene
		fig = plt.figure()
		ax = fig.gca(projection='3d')
		ax.set_aspect("equal")
		
		ax.set_xlabel('X (horizontal in mm)')
		ax.set_ylabel('Y (vertical in mm)')
		ax.set_zlabel('Z (depth in mm)')
		
		colorConverter = ColorConverter()
		
		for data in dataset:
			result = self.featureExtractor.getFeatures(data)
			
			# Processed data
			fingerTipCoordinates = self.featureExtractor.fingerTip[0]
			eyeCoordinates = self.featureExtractor.eyePosition[0]
			targetCoordinates = data.target
			depthMap = data.depth_map
			
			fingerTipCoordinates.append(self.utils.getDepthFromMap(depthMap, fingerTipCoordinates))
			eyeCoordinates.append(self.utils.getDepthFromMap(depthMap, eyeCoordinates))
			
			closest = self.trigonometry.findIntersection(fingerTipCoordinates, eyeCoordinates, targetCoordinates, self.expectedRadius)
			
			
			if closest != None:
				x = closest[0]-targetCoordinates[0]
				y = closest[1]-targetCoordinates[1]
				z = closest[2]-targetCoordinates[2]
				
				distance = self.trigonometry.findIntersectionDistance(fingerTipCoordinates, eyeCoordinates, targetCoordinates, self.expectedRadius)
				
				red = 1-(distance/200)
				if red < 0:
					red = 0
				elif red > 1:
					red = 1
				
				blue = 0+(distance/200)
				if blue < 0:
					blue = 0
				elif blue > 1:
					blue = 1
				
				cc = colorConverter.to_rgba((red,0,blue), 0.4)
				
				# Draw the impact point
				ax.scatter(x, y, z, color=cc, marker="o", s=50)
		
		# Draw the target point
		ax.scatter(0, 0, 0, c="#000000", marker="o", color="#000000", s=100)
		
		plt.show()
开发者ID:EdwardBetts,项目名称:pointing-gesture-recognition,代码行数:60,代码来源:accuracy.py

示例6: _plot_ribbon_using_bezier

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def _plot_ribbon_using_bezier(ax, zorder, points1, points2, color1="gray",
                              color2="gray", lw=1):
    """ Draw ribbon for alluvial diagram (see plot_alluvial)

    Parameters
    ----------
    ax : a matplotlib.axes object
    zorder : float
        the zorder for the ribbon
    points1 : iterable of float tuples
        the points, which determine the first line of the Bezier ribbon
    points2 : iterable of float tuples
        the points, which determine the second line of the Bezier ribbon
    color1 : a matplotlib compliant color definition
        color for the left side of the ribbon
    color1 : a matplotlib compliant color definition
        color for the right side of the ribbon
    lw : float
        linewidth for the bezier borders
    """
    cc = ColorConverter()
    color1 = np.array(cc.to_rgba(color1))
    color2 = np.array(cc.to_rgba(color2))
    tRange = np.linspace(0, 1, 100)
    xpointsList = []
    ypointsList = []
    for points in [points1, points2]:
        points = np.array(points)
        p1 = points[0]
        p2 = points[1]
        p3 = points[2]
        p4 = points[3]
        allPoints = (p1[:, np.newaxis] * (1 - tRange) ** 3 + p2[:, np.newaxis]
                     * (3 * (1 - tRange) ** 2 * tRange) + p3[:, np.newaxis] *
                     (3 * (1 - tRange) * tRange ** 2) + p4[:, np.newaxis] *
                     tRange ** 3)
        xpoints = allPoints[0]
        xpointsList.append(xpoints)
        ypoints = allPoints[1]
        ypointsList.append(ypoints)
        ax.plot(xpoints, ypoints, "0.85", lw=lw, zorder=zorder + 0.5)
    xpoints = xpointsList[0]
    if (mpl.colors.colorConverter.to_rgba_array(color1) ==
            mpl.colors.colorConverter.to_rgba_array(color2)).all():
        ax.fill_between(xpoints, ypointsList[0], ypointsList[1], lw=lw,
                        facecolor=color1, edgecolor=color1, zorder=zorder)
    else:
        for i in range(len(tRange) - 1):
            #mean = (tRange[i]+tRange[i+1])*0.5
            xnow = np.mean(xpoints[i:i + 2])
            norm_mean = (xnow - xpoints[0]) / (xpoints[-1] - xpoints[0])
            color = color1 * (1 - norm_mean) + color2 * norm_mean
            ax.fill_between(xpoints[i:i + 2], ypointsList[0][i:i + 2],
                            ypointsList[1][i:i + 2], lw=lw, facecolor=color,
                            edgecolor=color, zorder=zorder)
开发者ID:CxAalto,项目名称:verkko,代码行数:57,代码来源:alluvial.py

示例7: set_legend_to_bw

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def set_legend_to_bw(leg, style, colormap, line_style='continuous'):
    """
    Takes the figure legend and converts it to black and white. Note that
    it currently only converts lines to black and white, other artist 
    intances are currently not being supported, and might cause errors or
    other unexpected behavior.
    
    Parameters
    ----------
    leg : legend
    style : {GREYSCALE, HATCHING}
    colormap : dict
               mapping of color to B&W rendering
    line_style: str
                linestyle to use for converting, can be continuous, black
                or None
                
    # TODO:: None is strange as a value, and should be field based, see
    # set_ax_lines_bw
    
    """
    color_converter = ColorConverter()

    if leg:
        if isinstance(leg, list):
            leg = leg[0]
    
        for element in leg.legendHandles:
            if isinstance(element, mpl.collections.PathCollection):
                rgb_orig = color_converter.to_rgb(element._facecolors[0])
                new_color = color_converter.to_rgba(colormap[rgb_orig]['fill'])
                element._facecolors = np.array((new_color,))
            elif isinstance(element, mpl.patches.Rectangle):
                rgb_orig = color_converter.to_rgb(element._facecolor)
                
                if style==HATCHING:
                    element.update({'alpha':1})
                    element.update({'facecolor':'none'})
                    element.update({'edgecolor':'black'})
                    element.update({'hatch':colormap[rgb_orig]['hatch']})
                elif style==GREYSCALE:
                    ema_logging.info(colormap.keys())
                    element.update({'facecolor':colormap[rgb_orig]['fill']})
                    element.update({'edgecolor':colormap[rgb_orig]['fill']})
            else:
                line = element
                orig_color = line.get_color()
                
                line.set_color('black')
                if not line_style=='continuous':
                    line.set_dashes(colormap[orig_color]['dash'])
                    line.set_marker(colormap[orig_color]['marker'])
                    line.set_markersize(MARKERSIZE)
开发者ID:JamesPHoughton,项目名称:EMAworkbench,代码行数:55,代码来源:b_and_w_plotting.py

示例8: visualizeHaarFeatures

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def visualizeHaarFeatures():
    fig = figure()
    ax = fig.add_subplot(111)
    ax.set_xlim([0, 1])  # pylab.xlim([-400, 400])
    ax.set_ylim([0, 1])  # pylab.ylim([-400, 400])
    patches = []

    cc = ColorConverter()
    outer = cc.to_rgba("#BFCBDE", alpha=0.5)
    inner = cc.to_rgba("RED", alpha=0.5)

    for row in generateHaarFeatures(100):
        #print row
        patches.append(
            gca().add_patch(Rectangle((row[0], row[1]), row[2]-row[0], row[3]-row[1], color=outer)))
        patches.append(
            gca().add_patch(Rectangle((row[4], row[5]), row[6]-row[4], row[7]-row[5], color=inner)))
    p = collections.PatchCollection(patches)

    patches = ax.add_collection(p)

    show()
开发者ID:snuderl,项目名称:VideoTracking,代码行数:24,代码来源:haar_features.py

示例9: drawImpacts2D

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
	def drawImpacts2D(self, x=True, y=True, z=False):
		# Load the dataset
		dataset = self.datasetManager.loadDataset(self.datasetManager.getAccuracyComplete())
		
		plt.axis("equal")
		colorConverter = ColorConverter()
		
		for data in dataset:
			result = self.featureExtractor.getFeatures(data)
			
			# Processed data
			fingerTipCoordinates = self.featureExtractor.fingerTip[0]
			eyeCoordinates = self.featureExtractor.eyePosition[0]
			targetCoordinates = data.target
			depthMap = data.depth_map
			
			fingerTipCoordinates.append(self.utils.getDepthFromMap(depthMap, fingerTipCoordinates))
			eyeCoordinates.append(self.utils.getDepthFromMap(depthMap, eyeCoordinates))
			
			closest = self.trigonometry.findIntersection(fingerTipCoordinates, eyeCoordinates, targetCoordinates, self.expectedRadius)
			
			
			if closest != None:
				x = closest[0]-targetCoordinates[0]
				y = closest[1]-targetCoordinates[1]
				z = closest[2]-targetCoordinates[2]
				
				distance = self.trigonometry.findIntersectionDistance(fingerTipCoordinates, eyeCoordinates, targetCoordinates, self.expectedRadius)
				
				red = 1-(distance/200)
				if red < 0:
					red = 0
				elif red > 1:
					red = 1
				
				blue = 0+(distance/200)
				if blue < 0:
					blue = 0
				elif blue > 1:
					blue = 1
				
				cc = colorConverter.to_rgba((red,0,blue), 0.4)
				
				if not x:
					plt.scatter(y, z, color=cc, marker="o", s=50)
				elif not y:
					plt.scatter(x, z, color=cc, marker="o", s=50)
				else:
					plt.scatter(x, y, color=cc, marker="o", s=50)
		
		plt.show()
开发者ID:EdwardBetts,项目名称:pointing-gesture-recognition,代码行数:53,代码来源:accuracy.py

示例10: set_legend_to_bw

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def set_legend_to_bw(leg, style):
    """
    Takes the figure legend and converts it to black and white. Note that
    it currently only converts lines to black and white, other artist 
    intances are currently not being supported, and might cause errors or
    other unexpected behavior.
    
    Parameters
    ----------
    leg : legend
    style : {GREYSCALE, HATCHING}
    
    """
    color_converter = ColorConverter()
    colors = {}
    for key, value in color_converter.colors.items():
        colors[value] = key
    
    if leg:
        if isinstance(leg, list):
            leg = leg[0]
    
        for element in leg.legendHandles:
            if isinstance(element, mpl.collections.PathCollection):
                rgb_orig = color_converter.to_rgb(element._facecolors[0])
                origColor = colors[rgb_orig]
                new_color = color_converter.to_rgba(COLORMAP[origColor]['fill'])
                element._facecolors = np.array((new_color,))
            elif isinstance(element, mpl.patches.Rectangle):
                rgb_orig = color_converter.to_rgb(element._facecolor)
                c = colors[rgb_orig]
                
                if style==HATCHING:
                    element.update({'alpha':1})
                    element.update({'facecolor':'none'})
                    element.update({'edgecolor':'black'})
                    element.update({'hatch':COLORMAP[c]['hatch']})
                elif style==GREYSCALE:
                    element.update({'facecolor':COLORMAP[c]['fill']})
                    element.update({'edgecolor':COLORMAP[c]['fill']})

            else:
                line = element
                origColor = line.get_color()
                line.set_color('black')
                line.set_dashes(COLORMAP[origColor]['dash'])
                line.set_marker(COLORMAP[origColor]['marker'])
                line.set_markersize(MARKERSIZE)
开发者ID:MasterNicknak007,项目名称:EMAworkbench,代码行数:50,代码来源:b_and_w_plotting.py

示例11: _set_ax_polycollection_to_bw

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def _set_ax_polycollection_to_bw(collection, ax, style, colormap):
    '''helper function for converting a polycollection to black and white

    Parameters
    ----------
    collection : polycollection
    ax : axes
    style : {GREYSCALE, HATCHING}
    colormap : dict
               mapping of color to B&W rendering


    '''

    if style == GREYSCALE:
        color_converter = ColorConverter()
        for polycollection in ax.collections:
            orig_color = polycollection._original_facecolor

            try:
                mapping = colormap[orig_color]
            except BaseException:
                ema_logging.warning(
                    'no mapping specified for color: {}'.format(orig_color))
            else:
                new_color = color_converter.to_rgba(mapping['fill'])
                new_color = np.asarray([new_color])
                polycollection.update({'facecolors': new_color})
                polycollection.update({'edgecolors': new_color})
    elif style == HATCHING:
        orig_color = collection._original_facecolor

        try:
            mapping = colormap[orig_color]
        except BaseException:
            ema_logging.warning(
                'no mapping specified for color: {}'.format(orig_color))
        else:
            collection.update({'facecolors': 'none'})
            collection.update({'edgecolors': 'white'})
            collection.update({'alpha': 1})

            for path in collection.get_paths():
                p1 = mpl.patches.PathPatch(path, fc="none",
                                           hatch=colormap[orig_color]['hatch'])
                ax.add_patch(p1)
                p1.set_zorder(collection.get_zorder() - 0.1)
开发者ID:marcjaxa,项目名称:EMAworkbench,代码行数:49,代码来源:b_and_w_plotting.py

示例12: set_ax_patches_bw

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def set_ax_patches_bw(ax):
    """
    Take each patch in the axes, ax, and convert the face color to be 
    suitable for black and white viewing.
    
    Parameters
    ----------
    ax : axes
         The ax of which the patches needs to be transformed to B&W.
    
    """    
    
    color_converter = ColorConverter()
    
    for patch in ax.patches:
        rgb_orig = color_converter.to_rgb(patch._facecolor)
        new_color = color_converter.to_rgba(COLORMAP[rgb_orig]['fill'])
        
        patch._facecolor = new_color
开发者ID:feilos,项目名称:EMAworkbench,代码行数:21,代码来源:b_and_w_plotting.py

示例13: test

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def test():
    n = 1
    colors = ch.get_distinct_colors(n)
    assert len(colors) is 1
    n = 10
    colors = ch.get_distinct_colors(n)
    assert len(colors) is 10
    colors = ch.get_arbitrary_n_of_distinct_colors(11)
    assert len(colors) is 11
    colors = ch.get_qualitative_brewer_colors(12)
    assert len(colors) is 12
    colors2 = ch.get_qualitative_brewer_colors(10)
    # same first colors should be returned with 10-12 colors used:
    assert (colors[9] == colors2[-1]).all()
    
    
    cc = ColorConverter()
    for color in colors:
        assert len(cc.to_rgba(color)) is 4
开发者ID:CxAalto,项目名称:verkko,代码行数:21,代码来源:test_colorhelp.py

示例14: __init__

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
    def __init__(
            self,
            event_name,
            event_csv,
            colors,
            time_chunk_name='minutes',
            count_name='tweet_count'):

        # Set label parameters.
        self.event_name = event_name
        self.chunk_name = time_chunk_name
        self.count_name = count_name

        #Convert Colors to MPL format
        cv = ColorConverter()
        self.event_color = cv.to_rgba(colors[0])
        self.rumor_color = cv.to_rgba(colors[1])

        # Process the event CSV.
        self.event_counts = self.csv_to_counts(event_csv, event_csv=True)
        self.event_y = list(self.event_counts[self.count_name])
        self.event_x = range(self.event_counts.num_rows())
开发者ID:emCOMP,项目名称:rumor_analytics,代码行数:24,代码来源:CoverageExplorer.py

示例15: mpl_to_qt_color

# 需要导入模块: from matplotlib.colors import ColorConverter [as 别名]
# 或者: from matplotlib.colors.ColorConverter import to_rgba [as 别名]
def mpl_to_qt_color(color, alpha=None):
    """
    Convert a matplotlib color string into a Qt QColor object

    Parameters
    ----------
    color : str
       A color specification that matplotlib understands
    alpha : float
        Optional opacity. Float in range [0,1]

    Returns
    -------
    qcolor : ``QColor``
        A QColor object representing the converted color
    """
    if color in [None, 'none', 'None']:
        return QtGui.QColor(0, 0, 0, 0)

    cc = ColorConverter()
    r, g, b, a = cc.to_rgba(color)
    if alpha is not None:
        a = alpha
    return QtGui.QColor(r * 255, g * 255, b * 255, a * 255)
开发者ID:glue-viz,项目名称:glue,代码行数:26,代码来源:colors.py


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