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


Python PolyCollection.set_facecolor方法代码示例

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


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

示例1: plot_triangles

# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_facecolor [as 别名]
def plot_triangles(p, adjustLowerLeft=False, values=None, values_cmap=matplotlib.cm.jet, edgecolors='k'):
    """ Add mesh triangles to a pyplot plot
        
       @param p = object holding sww vertex information (from util.get_output)
       @param adjustLowerLeft = if TRUE, use spatial coordinates, otherwise use ANUGA internal coordinates     
       @param values = list or array of length(p.vols), or None. All triangles are assigned this value (for face plotting colors).
       @param values_cmap = colormap for faces [e.g. values_cmap = matplotlib.cm.get_cmap('spectral')]
       @param edgecolors = edge color for polygons (using matplotlib.colors notation). Use 'none' for no color
    """
    import matplotlib
    from matplotlib import pyplot as pyplot
    from matplotlib.collections import PolyCollection

    x0=p.xllcorner
    y0=p.yllcorner 

    # Make vertices for PolyCollection Object
    vertices = []
    for i in range(len(p.vols)):
        k1=p.vols[i][0]
        k2=p.vols[i][1]
        k3=p.vols[i][2]

        tri_coords = numpy.array([ [p.x[k1], p.y[k1]], [p.x[k2], p.y[k2]], [p.x[k3], p.y[k3]] ])
        if adjustLowerLeft:
            tri_coords[:,0] = tri_coords[:,0] + x0
            tri_coords[:,1] = tri_coords[:,1] + y0

        vertices.append(tri_coords)
     
    # Make PolyCollection 
    if values is None: 
        all_poly = PolyCollection( vertices, array = numpy.zeros(len(vertices)), 
            edgecolors=edgecolors)
        all_poly.set_facecolor('none')
    else:
        try:
            lv = len(values)
        except:
            values = numpy.array(len(p.vols)*[values])
            lv = len(values)

        msg = 'len(values) must be the same as len(p.vols) (or values can be a constant)'
        assert lv==len(p.vols), msg
        all_poly = PolyCollection( vertices, array = values, cmap = values_cmap, 
            edgecolors=edgecolors)

    # Add to plot
    # FIXME: To see the triangles, this might require that the user does
    # something else to the plot?
    pyplot.gca().add_collection(all_poly)
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:53,代码来源:plot_utils.py

示例2: ScatterPlotCC

# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_facecolor [as 别名]
class ScatterPlotCC(ScatterPlot):

    def get_polygon(self, x, y, c):
        color_map = ('c', 'r', 'b', 'm', 'y', 'g')
        d = defaultdict(list)

        for p, cc in zip(zip(x, y), c):
            d[cc].append(p)

        polygons = []
        colors = []
        for k in set(c):
            if len(d[k]) == 2:
                pt1 = d[k][0]
                pt2 = d[k][1]
                dist = math.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2)
                xmid = (pt1[0] + pt2[0]) / 2
                ymid = (pt1[1] + pt2[1]) / 2
                polygons.append(d[k])
                colors.append(color_map[k])
            elif len(d[k]) == 1:
                pass
            else:
                ch = ConvexHull(d[k])
                points = ch.points
                pts = zip(points[ch.vertices, 0], points[ch.vertices, 1])
                polygons.append(pts)
                colors.append(color_map[k])

        return polygons, colors

    def setup_plot(self):
        ax = plt.gca()
        x, y, c = next(self.stream)
        po, co = self.get_polygon(x, y, c)
        self.poly = PolyCollection(po, facecolors = co, edgecolors='none')

        ax.add_collection(self.poly)
        self.scat = ax.scatter(x, y, c='k', marker = self.marker, s = 25)
        return self.scat

    def update_plot(self):
        x, y, c = next(self.stream)
        new_data = np.array(zip(x, y))
        po, co = self.get_polygon(x, y, c)
        self.poly.set_facecolor(co)
        self.poly.set_verts(po)
        self.scat.set_offsets(new_data)
        return self.scat
开发者ID:DSRC-GPU,项目名称:Gephi-ForceAtlas2,代码行数:51,代码来源:connected_comp_plot.py

示例3: plotmap

# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_facecolor [as 别名]
def plotmap(shpfile,color='0.5',fieldname='FID',convert=None,zone=15,\
    scale=1.,offset=0.,subset=1):
    """
    Plots a map layer from a polygon or multipolygon shapefile
    
    Usage:
        plotmap(shpfile,color='0.5',fieldname='FID',convert=None,zone=15)
        
        convert = 'll2utm' or 'utm2ll'
        zone = utm zone number
    """
    
    from matplotlib.collections import PolyCollection
    
    # Read the shapefile
    xy,marker = readShpPoly(shpfile,FIELDNAME=fieldname)
    
    if convert=='utm2ll':
        ll=[]
        for xytmp in xy:
            ll.append(utm2ll(xytmp,zone,CS='WGS84',north=True))
        xy=ll
    elif convert=='ll2utm':
        ll=[]
        for xytmp in xy:
            ll.append(ll2utm(xytmp,zone,CS='WGS84',north=True))
        xy=ll
        
    for ii in range(len(xy)):
        xy[ii] = xy[ii][::subset]*scale+offset

    # Add the polygons to the current axis as a series of patches
    fig = plt.gcf()
    ax = fig.gca()
    
    collection = PolyCollection(xy)
    collection.set_facecolor(color)
    #collection.set_rasterized(True)
    ax.add_collection(collection)
    #ax.axis('equal')
    
    return ax, collection
开发者ID:jadelson,项目名称:suntanspy,代码行数:44,代码来源:maptools.py

示例4: set_facecolor

# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_facecolor [as 别名]
 def set_facecolor(self, colors):
     PolyCollection.set_facecolor(self, colors)
     self._facecolors3d = PolyCollection.get_facecolor(self)
开发者ID:Aharobot,项目名称:matplotlib,代码行数:5,代码来源:art3d.py

示例5: PolyCollection

# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_facecolor [as 别名]
              else:
                if lat_distance:
                  if geomag_distance:
                    target_mag=aacgm.Convert(target_lat,target_lon,0,year=2010,flag=0)
                    p1color_ax.plot([p.date2num(startday),p.date2num(endday)],
                      [target_mag[0],target_mag[0]],linewidth=4,linestyle="--",color="k",alpha=0.5)
                  else:
                    p1color_ax.plot([p.date2num(startday),p.date2num(endday)],
                      [target_lat,target_lat],linewidth=4,linestyle="--",color="k",alpha=0.5)

            p.axes(p2color_ax)
            pixs=N.array(p2pixels)
            colors=p2values
            coll = PolyCollection(pixs,edgecolors='none',linewidths=0.0,zorder=10)
            coll.set_antialiased(False)
            coll.set_facecolor(colors)
            coll.set_alpha(1)
            p2color_ax.add_collection(coll)
            p2color_ax.autoscale_view() 
            p2color_ax.xaxis.set_major_formatter(dateFmt)
            p2color_ax.set_xlim(p.date2num(startday), p.date2num(endday))
            p2color_ax.set_ylim(plotdict["min_rang"],plotdict["max_rang"])
            p2color_ax.xaxis.set_major_locator(tick2_minute_interval)
            p2color_locator=MaxNLocator(nbins=6,prune='both',integer=True)
            p2color_ax.yaxis.set_major_locator(p2color_locator)
            p2color_ax.set_xticklabels([])
#            p2color_ax.set_xticks([])
            p2color_ax.yaxis.grid(True, linestyle='-', which='major', color='lightgrey',alpha=0.5)
            p2color_ax.xaxis.grid(True, linestyle='-', which='major', color='lightgrey',alpha=0.5)
            print "pcolor done"
开发者ID:UAF-SuperDARN-OPS,项目名称:UAF_Server_Scripts,代码行数:32,代码来源:poly-rti.py

示例6: plot_geocol_mpl

# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_facecolor [as 别名]
def plot_geocol_mpl(gc, color=None, facecolor='0.3', edgecolor='0.7',
        alpha=1., linewidth=0.2, marker='o', marker_size=20,
        ax=None, figsize=(9,9)):
    '''
    Plot geographical data from the `geometry` column of a PySAL geotable to a
    matplotlib backend.

    ...

    Arguments
    ---------
    gc          : DataFrame
                  GeoCol with data to be plotted.
    color       : str/tuple/Series
                  [Optional. Default=None] Wrapper that sets both `facecolor`
                  and `edgecolor` at the same time. If set, `facecolor` and
                  `edgecolor` are ignored. It allows for either a single color
                  or a Series of the same length as `gc` with colors, indexed
                  on `gc.index`.
    facecolor   : str/tuple/Series
                  [Optional. Default='0.3'] Color for polygons and points. It
                  allows for either a single color or a Series of the same
                  length as `gc` with colors, indexed on `gc.index`.
    edgecolor   : str/tuple/Series
                  [Optional. Default='0.7'] Color for the polygon and point
                  edges. It allows for either a single color or a Series of
                  the same length as `gc` with colors, indexed on `gc.index`.
    alpha       : float/Series
                  [Optional. Default=1.] Transparency. It allows for either a
                  single value or a Series of the same length as `gc` with
                  colors, indexed on `gc.index`.
    linewidth   : float/Series
                  [Optional. Default=0.2] Width(s) of the lines in polygon and
                  line plotting (not applicable to points). It allows for
                  either a single value or a Series of the same length as `gc`
                  with colors, indexed on `gc.index`.
    marker      : 'o'
    marker_size : int
    ax          : AxesSubplot
                  [Optional. Default=None] Pre-existing axes to which append the
                  collections and setup
    figsize     : tuple
                  w,h of figure
    '''
    geom = type(gc.iloc[0])
    if color is not None:
        facecolor = edgecolor = color
    draw = False
    if not ax:
        f, ax = plt.subplots(1, figsize=figsize)
        draw = True
    # Geometry plotting
    patches = []
    ids = []
    ## Polygons
    if geom == ps.cg.shapes.Polygon:
        for id, shape in gc.iteritems():
            for ring in shape.parts:
                xy = np.array(ring)
                patches.append(xy)
                ids.append(id)
        mpl_col = PolyCollection(patches)
    ## Lines
    elif geom == ps.cg.shapes.Chain:
        for id, shape in gc.iteritems():
            for xy in shape.parts:
                patches.append(xy)
                ids.append(id)
        mpl_col = LineCollection(patches)
        facecolor = 'None'
    ## Points
    elif geom == ps.cg.shapes.Point:
        edgecolor = facecolor
        xys = np.array(zip(*gc)).T
        ax.scatter(xys[:, 0], xys[:, 1], marker=marker,
                s=marker_size, c=facecolor, edgecolors=edgecolor,
                linewidths=linewidth)
        mpl_col = None
    # Styling mpl collection (polygons & lines)
    if mpl_col:
        if type(facecolor) is pd.Series:
            facecolor = facecolor.reindex(ids)
        mpl_col.set_facecolor(facecolor)
        if type(edgecolor) is pd.Series:
            edgecolor = edgecolor.reindex(ids)
        mpl_col.set_edgecolor(edgecolor)
        if type(linewidth) is pd.Series:
            linewidth = linewidth.reindex(ids)
        mpl_col.set_linewidth(linewidth)
        if type(alpha) is pd.Series:
            alpha = alpha.reindex(ids)
        mpl_col.set_alpha(alpha)

        ax.add_collection(mpl_col, autolim=True)
        ax.autoscale_view()
    ax.set_axis_off()
    if draw:
        plt.axis('equal')
        plt.show()
    return None
开发者ID:lanselin,项目名称:pysal,代码行数:102,代码来源:mapping.py


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