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


Python collections.PatchCollection方法代码示例

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


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

示例1: construct_ball_trajectory

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def construct_ball_trajectory(var, r=1., cmap='Blues', start_color=0.4, shape='c'):
    # https://matplotlib.org/examples/color/colormaps_reference.html
    patches = []
    for pos in var:
        if shape == 'c':
            patches.append(mpatches.Circle(pos, r))
        elif shape == 'r':
            patches.append(mpatches.RegularPolygon(pos, 4, r))
        elif shape == 's':
            patches.append(mpatches.RegularPolygon(pos, 6, r))

    colors = np.linspace(start_color, .9, len(patches))
    collection = PatchCollection(patches, cmap=cm.get_cmap(cmap), alpha=1.)
    collection.set_array(np.array(colors))
    collection.set_clim(0, 1)
    return collection 
开发者ID:simonkamronn,项目名称:kvae,代码行数:18,代码来源:plotting.py

示例2: visualize_poly

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def visualize_poly(poly_list, mask, out_path):
    """
    Visualizes the polygons produced by mask_to_poly() and save them at the specified path

    Args:
        poly_list: list of shapely.geometry.polygon.Polygon on this image
        mask: the predicted mask, needed for laying out the axes
        out_path: path at which the visualization of the list of polygons is to be saved
    """
    fig, ax = plt.subplots()
    ax.imshow(mask, alpha=0)  # don't show the mask, but need this to be added to the axes for polygons to show up
    patch_list = []

    for poly in poly_list:
        x, y = poly.exterior.coords.xy
        xy = np.column_stack((x, y))
        polygon = matplotlib.patches.Polygon(xy, linewidth=1, edgecolor='b', facecolor='none')
        patch_list.append(polygon)

    p = PatchCollection(patch_list, cmap=matplotlib.cm.jet, alpha=1)
    ax.add_collection(p)

    fig.savefig(out_path, bbox_inches='tight')
    plt.close(fig) 
开发者ID:yangsiyu007,项目名称:SpaceNetExploration,代码行数:26,代码来源:polygonize.py

示例3: plot_filled_polygons

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def plot_filled_polygons(self,polygons, facecolour='green', edgecolour='black', linewidth=1, alpha=0.5):
        """
        This function plots a series of shapely polygons but fills them in

        Args:
            ax_list: list of axes
            polygons: list of shapely polygons

        Author: FJC
        """
        from shapely.geometry import Polygon
        from descartes import PolygonPatch
        from matplotlib.collections import PatchCollection

        print('Plotting the polygons...')

        #patches = []
        for key, poly in polygons.items():
            this_patch = PolygonPatch(poly, fc=facecolour, ec=edgecolour, alpha=alpha)
            self.ax_list[0].add_patch(this_patch) 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:22,代码来源:PlottingRaster.py

示例4: onclick_release

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def onclick_release(self, event):

        if any([x.in_axes(event) for x in self.button_axes]) or self.selected_poly:
            return

        if hasattr(self, 'r_x') and hasattr(self, 'r_y') and None not in [self.r_x, self.r_y, event.xdata, event.ydata]:
            if np.abs(event.xdata - self.r_x)>10 and np.abs(event.ydata - self.r_y)>10: # 10 pixels limit for rectangle creation
                if len(self.points)<4:

                    self.right_click=True
                    self.fig.canvas.mpl_disconnect(self.click_id)
                    self.click_id = None
                    bbox = [np.min([event.xdata, self.r_x]), np.min([event.ydata, self.r_y]), np.max([event.xdata, self.r_x]), np.max([event.ydata, self.r_y])]
                    self.r_x = self.r_y = None

                    self.points = [bbox[0], bbox[1], bbox[0], bbox[3], bbox[2], bbox[3], bbox[2], bbox[1], bbox[0], bbox[1]]
                    self.p = PatchCollection([Polygon(self.points_to_polygon(), closed=True)], facecolor='red', linewidths=0, alpha=0.4)
                    self.ax.add_collection(self.p)
                    self.fig.canvas.draw() 
开发者ID:hanskrupakar,项目名称:COCO-Style-Dataset-Generator-GUI,代码行数:21,代码来源:segment.py

示例5: submit

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def submit(self, event):

        if not self.right_click:
            print ('Right click before submit is a must!!')
        else:

            self.text+=self.radio.value_selected+'\n'+'%.2f'%self.find_poly_area()+'\n'+self.print_points()+'\n\n'
            self.right_click = False
            #print (self.points)

            self.lines, self.circles = [], []
            self.click_id = fig.canvas.mpl_connect('button_press_event', self.onclick)

            self.polys.append(Polygon(self.points_to_polygon(), closed=True, color=np.random.rand(3), alpha=0.4, fill=True))
            if self.submit_p:
                self.submit_p.remove()
            self.submit_p = PatchCollection(self.polys, cmap=matplotlib.cm.jet, alpha=0.4)
            self.ax.add_collection(self.submit_p)
            self.points = [] 
开发者ID:hanskrupakar,项目名称:COCO-Style-Dataset-Generator-GUI,代码行数:21,代码来源:segment.py

示例6: _plot_bursts

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def _plot_bursts(d, i, tmin_clk, tmax_clk, pmax=1e3, pmin=0, color="#999999",
                 ytext=20):
    """Highlights bursts in a timetrace plot."""
    b = d.mburst[i]
    if b.num_bursts == 0:
        return
    burst_mask = (tmin_clk < b.start) * (b.start < tmax_clk)
    bs = b[burst_mask]
    burst_indices = np.where(burst_mask)[0]
    start = bs.start * d.clk_p
    end = bs.stop * d.clk_p
    R = []
    width = end - start
    ax = gca()
    for b, bidx, s, w, sign, va in zip(bs, burst_indices, start, width,
                                       cycle([-1, 1]),
                                       cycle(['top', 'bottom'])):
        r = Rectangle(xy=(s, pmin), height=pmax - pmin, width=w)
        r.set_clip_box(ax.bbox)
        r.set_zorder(0)
        R.append(r)
        ax.text(s, sign * ytext, _burst_info(d, i, bidx), fontsize=6, rotation=45,
                horizontalalignment='center', va=va)
    ax.add_artist(PatchCollection(R, lw=0, color=color)) 
开发者ID:tritemio,项目名称:FRETBursts,代码行数:26,代码来源:burst_plot.py

示例7: __init__

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def __init__(self,xcoord,ycoord,**kwargs):
        collections.PatchCollection.__init__(self,[],**kwargs)
        tol = 0.02
        _xdata1 = np.array([xcoord-tol,xcoord,xcoord+tol])
        _ydata1 = np.array([ycoord-tol,ycoord,ycoord-tol])
        _xdata2 = np.array([xcoord-tol,xcoord,xcoord-tol])
        _ydata2 = np.array([ycoord-tol,ycoord,ycoord+tol])
        # Polygons
        p1 = patches.Polygon(zip(_xdata1,_ydata1))
        p1.set_color("r")
        p2 = patches.Polygon(zip(_xdata2,_ydata2))
        #print p1,p2
        #p2.set_color("g")
        # Set data
        self.set_paths((p1,p2))
        self.set_color("k")
        #self.set_marker("-")
        #self.set_mfc('r')
        #self.set_ms(10) 
开发者ID:JorgeDeLosSantos,项目名称:nusa,代码行数:21,代码来源:graph.py

示例8: plot_density_rectange

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def plot_density_rectange(ax, cmap, density, fig, resolution, time_from, time_to):
    """
    Auxiliar function to plot_compared_intervals_ahead
    """
    from matplotlib.patches import Rectangle
    from matplotlib.collections import PatchCollection
    patches = []
    colors = []
    for x in density.index:
        for y in density.columns:
            s = Rectangle((time_from + x, y), 1, resolution, fill=True, lw = 0)
            patches.append(s)
            colors.append(density[y][x]*5)
    pc = PatchCollection(patches=patches, match_original=True)
    pc.set_clim([0, 1])
    pc.set_cmap(cmap)
    pc.set_array(np.array(colors))
    ax.add_collection(pc)
    cb = fig.colorbar(pc, ax=ax)
    cb.set_label('Density') 
开发者ID:PYFTS,项目名称:pyFTS,代码行数:22,代码来源:Util.py

示例9: plot_cloud

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def plot_cloud(self, Y, facecolor='0.8', edgecolor='0.8', alpha=0.5, edgelinestyle='-'):
		### create patches:
		y0,y1       = Y
		x,y0,y1     = self.x.tolist(), y0.tolist(), y1.tolist()
		x           = [x[0]]  + x  + [x[-1]]
		y0          = [y0[0]] + y0 + [y0[-1]]
		y1          = [y1[0]] + y1 + [y1[-1]]
		y1.reverse()
		### concatenate:
		x1          = np.copy(x).tolist()
		x1.reverse()
		x,y         = x + x1, y0 + y1
		patches     = PatchCollection(   [  Polygon(  np.array([x,y]).T  )  ], edgecolors=None)
		### plot:
		self.ax.add_collection(patches)
		pyplot.setp(patches, facecolor=facecolor, edgecolor=edgecolor, alpha=alpha, linestyle=edgelinestyle)
		return patches 
开发者ID:0todd0000,项目名称:spm1d,代码行数:19,代码来源:_plot.py

示例10: plot_polygon

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def plot_polygon(ax, x, **kwargs):
    ax.add_collection(PatchCollection([patches.Polygon(x, True)], **kwargs)) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:4,代码来源:util.py

示例11: showAnns

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def showAnns(self, objects, imgId, range):
        """
        :param catNms: category names
        :param objects: objects to show
        :param imgId: img to show
        :param range: display range in the img
        :return:
        """
        img = self.loadImgs(imgId)[0]
        plt.imshow(img)
        plt.axis('off')

        ax = plt.gca()
        ax.set_autoscale_on(False)
        polygons = []
        color = []
        circles = []
        r = 5
        for obj in objects:
            c = (np.random.random((1, 3)) * 0.6 + 0.4).tolist()[0]
            poly = obj['poly']
            polygons.append(Polygon(poly))
            color.append(c)
            point = poly[0]
            circle = Circle((point[0], point[1]), r)
            circles.append(circle)
        p = PatchCollection(polygons, facecolors=color, linewidths=0, alpha=0.4)
        ax.add_collection(p)
        p = PatchCollection(polygons, facecolors='none', edgecolors=color, linewidths=2)
        ax.add_collection(p)
        p = PatchCollection(circles, facecolors='red')
        ax.add_collection(p) 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:34,代码来源:DOTA.py

示例12: add_collection3d

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def add_collection3d(self, col, zs=0, zdir='z'):
        '''
        Add a 3D collection object to the plot.

        2D collection types are converted to a 3D version by
        modifying the object and adding z coordinate information.

        Supported are:
            - PolyCollection
            - LineColleciton
            - PatchCollection
        '''
        zvals = np.atleast_1d(zs)
        if len(zvals) > 0 :
            zsortval = min(zvals)
        else :
            zsortval = 0   # FIXME: Fairly arbitrary. Is there a better value?

        # FIXME: use issubclass() (although, then a 3D collection
        #       object would also pass.)  Maybe have a collection3d
        #       abstract class to test for and exclude?
        if type(col) is mcoll.PolyCollection:
            art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(zsortval)
        elif type(col) is mcoll.LineCollection:
            art3d.line_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(zsortval)
        elif type(col) is mcoll.PatchCollection:
            art3d.patch_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(zsortval)

        Axes.add_collection(self, col) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:34,代码来源:axes3d.py

示例13: bring_prev

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def bring_prev(self, event):

        if not self.feedback:

            poly_verts, self.objects = return_info(self.img_paths[self.index-1][:-3]+'txt')

            for num in poly_verts:
                self.existing_polys.append(Polygon(num, closed=True, alpha=0.5, facecolor='red'))

                pat = PatchCollection([Polygon(num, closed=True)], facecolor='green', linewidths=0, alpha=0.6)
                self.ax.add_collection(pat)
                self.existing_patches.append(pat) 
开发者ID:hanskrupakar,项目名称:COCO-Style-Dataset-Generator-GUI,代码行数:14,代码来源:segment.py

示例14: make_projection_available

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def make_projection_available(projection):
    avail_projections = {'2d', '3d'}
    if projection not in avail_projections:
        raise ValueError(f'choose projection from {avail_projections}')
    if projection == '2d':
        return

    from io import BytesIO
    from matplotlib import __version__ as mpl_version
    from mpl_toolkits.mplot3d import Axes3D

    fig = Figure()
    ax = Axes3D(fig)

    circles = PatchCollection([Circle((5, 1)), Circle((2, 2))])
    ax.add_collection3d(circles, zs=[1, 2])

    buf = BytesIO()
    try:
        fig.savefig(buf)
    except ValueError as e:
        if not 'operands could not be broadcast together' in str(e):
            raise e
        raise ValueError(
            'There is a known error with matplotlib 3d plotting, '
            f'and your version ({mpl_version}) seems to be affected. '
            'Please install matplotlib==3.0.2 or wait for '
            'https://github.com/matplotlib/matplotlib/issues/14298'
        ) 
开发者ID:theislab,项目名称:scanpy,代码行数:31,代码来源:_utils.py

示例15: test_mixed_collection

# 需要导入模块: from matplotlib import collections [as 别名]
# 或者: from matplotlib.collections import PatchCollection [as 别名]
def test_mixed_collection():
    from matplotlib import patches
    from matplotlib import collections

    x = list(xrange(10))

    # First illustrate basic pyplot interface, using defaults where possible.
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    c = patches.Circle((8, 8), radius=4, facecolor='none', edgecolor='green')

    # PDF can optimize this one
    p1 = collections.PatchCollection([c], match_original=True)
    p1.set_offsets([[0, 0], [24, 24]])
    p1.set_linewidths([1, 5])

    # PDF can't optimize this one, because the alpha of the edge changes
    p2 = collections.PatchCollection([c], match_original=True)
    p2.set_offsets([[48, 0], [-32, -16]])
    p2.set_linewidths([1, 5])
    p2.set_edgecolors([[0, 0, 0.1, 1.0], [0, 0, 0.1, 0.5]])

    ax.patch.set_color('0.5')
    ax.add_collection(p1)
    ax.add_collection(p2)

    ax.set_xlim(0, 16)
    ax.set_ylim(0, 16) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:31,代码来源:test_axes.py


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