當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。