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


Python LineCollection.set_linestyle方法代码示例

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


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

示例1: plotcf

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
def plotcf(grid, phase, modulus, darken=None, axes=None, linestylep="solid", linewidthp=1, color="k", **kwargs):
    r"""Plot the modulus of a complex valued function
    :math:`f:\mathbb{R} \rightarrow \mathbb{C}`
    together with its phase in a color coded fashion.

    :param grid: The grid nodes of the real domain R
    :param phase: The phase of the complex domain result f(grid)
    :param modulus: The modulus of the complex domain result f(grid)
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.
    :param linestylep: The line style of the phase curve.
    :param linewidthp: The line width of the phase curve.
    :param color: The color of the phase curve.
    """
    # Color mapping
    rgb_colors = color_map(modulus, phase=phase, modulus=modulus, darken=darken)

    # Put all the vertical line into a collection
    segments = [array([[node, 0], [node, value]]) for node, value in zip(grid, modulus)]
    line_segments = LineCollection(segments)

    # Set some properties of the lines
    rgb_colors = line_segments.to_rgba(rgb_colors)
    line_segments.set_color(rgb_colors[0])
    line_segments.set_linestyle(linestylep)
    line_segments.set_linewidth(linewidthp)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Plot the phase
    axes.add_collection(line_segments)
    # Plot the modulus
    axes.plot(grid, modulus, color=color, **kwargs)
开发者ID:Bredoto,项目名称:WaveBlocksND,代码行数:37,代码来源:plotcf.py

示例2: set_linestyle

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
 def set_linestyle(self, v):
     if v is None or v == 'None':
        self._nodraw = True
     else:
        self._nodraw = False
        LineCollection.set_linestyle(self, v)
     self._cz_linesytle_name = v
开发者ID:piScope,项目名称:piScope,代码行数:9,代码来源:cz_linecollection.py

示例3: draw_shp_polygons

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
    def draw_shp_polygons(self, shp_filepath, linewidths=0.2, colors='k', antialiaseds=None, linestyles='solid'):
        """
        Draw a shapefile containing polygons
        """   
        # Read the shapefile as shapes and records. For each polygon in shapes, draw its boundaries
        r = shapefile.Reader(shp_filepath)
        shapes = r.shapes()
        records = r.records()

        for record, shape in zip(records, shapes):
            lons, lats = zip(*shape.points)
            data = [(x, y) for x, y in zip(*self(lons, lats))]
            
            # shape.parts is a list containing the starting index of each part of shape (e.g. a lake inside the shape) on xy_pts. If shape contains only 1 part, a list containing 0 is returned.
            if len(shape.parts) == 1: 
                segs = [data, ]
            else:
                segs = []
                for npart in range(1, len(shape.parts)):
                    ix1 = shape.parts[npart-1]
                    ix2 = shape.parts[npart]
                    segs.append(data[ix1:ix2])
                    
                segs.append(data[ix2: ])
            
            lines = LineCollection(segs, antialiaseds = [1, ])
            lines.set_edgecolors(colors)
            lines.set_linestyle(linestyles)
            lines.set_linewidth(linewidths)
            self.ax.add_collection(lines)
开发者ID:resudirga,项目名称:dfd-nic,代码行数:32,代码来源:NICmap.py

示例4: generate_colored_lines

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
def generate_colored_lines(x,y,cval, color = ['orange','black'], ls = '-', lw = lw):

    cmap     = ListedColormap([color[0], 'purple', color[1]])
    norm     = BoundaryNorm([-0.1, 0.1, 0.9, 1.1], cmap.N)

    points   =  np.array([x, y]).T.reshape(-1,1,2)
    segments =  np.concatenate([points[:-1], points[1:]], axis=1)



    lc = LineCollection(segments, cmap = cmap, norm = norm)
    lc.set_array(cval)
    lc.set_linewidth(lw)
    lc.set_linestyle(ls)
    

    return lc
开发者ID:aemerick,项目名称:stars,代码行数:19,代码来源:plot_q_m.py

示例5: stemcf

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
def stemcf(grid, phase, modulus, darken=False, axes=None, linestylep="solid", linewidthp=2, color=None, markerp="o", **kwargs):
    r"""
    Stemplot the modulus of a complex valued function :math:`f:I \rightarrow C` together with its phase in a color coded fashion.

    :param grid: The grid nodes of the real domain R
    :param phase: The phase of the complex domain result f(grid)
    :param modulus: The modulus of the complex domain result f(grid)
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.
    :param linestylep: The line style of the phase curve.
    :param linewidthp: The line width of the phase curve.
    :param color: The color of the stemmed markers.
    :param markerp: The shape of the stemmed markers.

    .. note:: Additional keyword arguments are passe to the plot function.
    """
    # Color mapping
    rgb_colors = color_map(grid, phase=phase, modulus=modulus, darken=darken)

    # Put all the vertical line into a collection
    segments = [ array([[node,0], [node,value]]) for node, value in zip(grid, modulus) ]
    line_segments = LineCollection(segments)

    # Set some properties of the lines
    rgb_colors = line_segments.to_rgba(rgb_colors)
    line_segments.set_color(rgb_colors[0])
    line_segments.set_linestyle(linestylep)
    line_segments.set_linewidth(linewidthp)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Plot the phase
    axes.add_collection(line_segments)
    # Plot the modulus
    if color is None:
        # Scatter has a problem with complex data type, make sure values are purely real
        axes.scatter(grid, real(modulus), c=rgb_colors[0], **kwargs)
    else:
        axes.plot(grid, modulus, linestyle="", marker=markerp, color=color, **kwargs)
    # Plot the ground line
    axes.plot(grid, zeros(grid.shape), linestyle=linestylep, color="k", **kwargs)
开发者ID:WaveBlocks,项目名称:WaveBlocks,代码行数:45,代码来源:stemcf.py

示例6: plot_volume

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
def plot_volume(sim, vol=None, center=None, size=None,
                options=None, plot3D=False, label=None):

    options = options if options else def_plot_options

    fig=plt.gcf()
    ax=fig.gca(projection='3d') if plot3D else fig.gca()

    if vol:
       center, size = vol.center, vol.size
    v0=np.array([center.x, center.y])
    dx,dy=np.array([0.5*size.x,0.0]), np.array([0.0,0.5*size.y])
    if plot3D:
        zmin,zmax = ax.get_zlim3d()
        z0 = zmin + options['zrel']*(zmax-zmin)

    ##################################################
    # add polygon(s) to the plot to represent the volume
    ##################################################
    def add_to_plot(c):
        ax.add_collection3d(c,zs=z0,zdir='z') if plot3D else ax.add_collection(c)

    if size.x==0.0 or size.y==0.0:    # zero thickness, plot as line
        polygon = [ v0+dx+dy, v0-dx-dy ]
        add_to_plot( LineCollection( [polygon], colors=options['line_color'],
                                     linewidths=options['line_width'],
                                     linestyles=options['line_style']
                                   )
                   )
    else:
        if options['fill_color'] != 'none': # first copy: faces, no edges
            polygon = np.array([v0+dx+dy, v0-dx+dy, v0-dx-dy, v0+dx-dy])
            pc=PolyCollection( [polygon], linewidths=0.0)
            pc.set_color(options['fill_color'])
            pc.set_alpha(options['alpha'])
            add_to_plot(pc)
        if options['boundary_width']>0.0: # second copy: edges, no faces
            closed_polygon = np.array([v0+dx+dy, v0-dx+dy, v0-dx-dy, v0+dx-dy, v0+dx+dy])
            lc=LineCollection([closed_polygon])
            lc.set_linestyle(options['boundary_style'])
            lc.set_linewidth(options['boundary_width'])
            lc.set_edgecolor(options['boundary_color'])
            add_to_plot(lc)

    ######################################################################
    # attempt to autodetermine text rotation and alignment
    ######################################################################
    if label:
        x0, y0, r, h, v = np.mean(ax.get_xlim()),np.mean(ax.get_ylim()), 0, 'center', 'center'
        if size.y==0.0:
            v = 'bottom' if center.y>y0 else 'top'
        elif size.x==0.0:
            r, h = (270,'left') if center.x>x0 else (90,'right')
        if plot3D:
            ax.text(center.x, center.y, z0, label, rotation=r,
                    fontsize=options['fontsize'], color=options['line_color'],
                    horizontalalignment=h, verticalalignment=v)
        else:
            ax.text(center.x, center.y, label, rotation=r,
                    fontsize=options['fontsize'], color=options['line_color'],
                    horizontalalignment=h, verticalalignment=v)
开发者ID:oskooi,项目名称:meep,代码行数:63,代码来源:Visualization.py

示例7: main

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]

#.........这里部分代码省略.........
    q0, t0 = [7, 20], 0

    # arrivals dependent on poisson process
 #   ARRIVAL_1 = np.random.poisson(lam=LAMBDA_1)
 #   ARRIVAL_2 = np.random.poisson(lam=LAMBDA_2)

    # define indicator functions
    def I1(t): return 1.0 if np.mod(t,T) <= TIME_G_1 else 0.0
    def I2(t): return 1.0 if np.mod(t,T) >= TIME_G_1 else 0.0

    # define our right hand side
    def f(lam,rho,ind): return lam - rho*ind

    def RHS(t): return [f(LAMBDA_1,RHO_1,I1(t)), f(LAMBDA_2,RHO_2,I2(t))]

    def Solution(time,initial):
        queue = []
        for t in time:
            queue.append(RHS(t))
        fcn = np.reshape(queue,[len(time),2])
        sol = np.asarray(np.cumsum(fcn,axis=0)*dt + initial)
        sol[sol<0] = 0
        return sol
    # OBSOLETE : solution using numpy's cumsum
    # First part of the solution: time interval (t0,TIME_G_1)
    time = np.asarray(np.arange(t0,TIME_G_1,dt))
    Slope = RHS(time[1])
    sol = Solution(time,q0)
    # Lets try two cycles:
    numcycles = 3
    initial = sol[-1,]
    for j in range(2*numcycles-1):
        index = j+1
        start = np.mod(index,2)*TIME_G_1 + np.floor(index/2)*T
        end = np.mod(index+1,2)*TIME_G_1 + np.floor((index+1)/2)*T
        time_temp =  np.asarray(np.arange(start,end,dt))
        Slope.append(RHS(time_temp[1]))
        sol_temp = Solution(time_temp,initial)
        initial = sol_temp[-1,]
        time = np.concatenate((time,time_temp))
        sol = np.concatenate((sol,sol_temp))

    queues = np.squeeze(sol)
    print(Slope)
#    # set up scipy ode integrator
#    q=spi.ode(RHS).set_integrator("vode", method="bdf")
#    q.set_initial_value(q0, t0)
#
#    # iterate to get results
#    time = []
#    queues = []
#    while q.successful() and q.t < T:
#        step = q.t+dt
#        resp = q.integrate(q.t+dt)
#        resp[resp<0]=0
##        resp = max([resp,0])
#        time.append(step)
#        queues.append(resp)
#    #    print(step, resp)

    # generate pretty plots
    fig = plt.plot(time,queues[:,0], 'k-', label="Street 1", alpha=0.7)
    plt.plot(time, queues[:,1], 'k-', label="Street 2", alpha=0.7)
    ax = plt.gca()
    #fig = plt.plot(time, np.zeros(len(time)), 'w')
    #ax = plt.gca()
    ax.set_title("Queue Size vs. Time")
    ax.set_xlabel("Time (s)")
    ax.set_ylabel("Queue Size (# Cars)")
    # ax.legend(loc='best')
    # plt.axvspan(0, TIME_G_1, facecolor='r', alpha=0.2)
    # plt.axvspan(TIME_G_1, T, facecolor='g', alpha=0.2)
    # plt.axvline(x=TIME_G_1, color='g')

    #fig = plt.figure()
    #ax = fig.add_subplot(111)
    ax.set_title("Queue Size vs. Time")
    ax.set_xlabel("Time (s)")
    ax.set_ylabel("Queue Size (# Cars)")

    points1 = np.array([time, queues[:,0]]).T.reshape(-1,1,2)
    segments1 = np.concatenate([points1[:-1], points1[1:]], axis=1)
    lc1 = LineCollection(segments1, cmap=ListedColormap(['g','r']))
    lc1.set_array(time)
    lc1.set_linewidth(2)
    lc1.set_linestyle('-')
    ax.add_collection(lc1)

    points2 = np.array([time, queues[:,1]]).T.reshape(-1,1,2)
    segments2 = np.concatenate([points2[:-1], points2[1:]], axis=1)
    lc2 = LineCollection(segments2, cmap=ListedColormap(['r','g']))
    lc2.set_array(time)
    lc2.set_linewidth(2)
    lc2.set_linestyle('--')
    ax.add_collection(lc2)

    plt.xlim(time.min(), time.max())
    ax.grid()
    plt.savefig(str(i)+".png")
    plt.close()
开发者ID:TheKingInYellow,项目名称:pims_mmiw6_2016,代码行数:104,代码来源:traffic_2way.py

示例8: show_frac_charge

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]
def show_frac_charge(filename=None,bias=False,usevec=False,theta=0,dmu=0.01,target_block=(0,0),append=False,**kwargs):
    '''
    Show the fractional charge wave functions.
    '''
    model,expander=get_solving_system(evolutor_type='masked',periodic=False,**kwargs)
    if filename is None:
        filename='data/frac_W1%s_W2%s_U%s_N%s'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'))
    if not bias:
        ket_even=MPS.load(filename+'-even.dat')
        ket_odd=MPS.load(filename+'-odd.dat')
        #ket_odd=ket_odd-(ket_even.tobra(labels=ket_even.labels)*ket_odd).item()*ket_even
        #combine to left-right edge states.
        if usevec:
            ket_odd,ket_even=ket_odd.state,ket_even.state
        #else:
            #ket_odd.recanonicalize(tol=1e-8)
        ket_left=ket_even#(ket_even+exp(1j*theta)*ket_odd)/sqrt(2.)
        ket_right=ket_odd#(ket_even-exp(1j*theta)*ket_odd)/sqrt(2.)
        if not usevec:
            ket_left.recanonicalize(tol=1e-8)   #we must recanonicalize it, for it is not canonical!!!
            ket_right.recanonicalize(tol=1e-8)
            print ket_left
            print ket_right
            pls=[dos4mps(spaceconfig=expander.spaceconfig,ket=ket) for ket in [ket_left,ket_right]]
        else:
            pls=[dos4vec(spaceconfig=model.hgen.spaceconfig,ket=ket) for ket in [ket_left,ket_right]]
    else:
        suffix='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,target_block)
        filename_mps='data/mps_'+suffix
        print filename_mps
        fname='data/fracdos_'+suffix
        #suffix2='W1%s_W2%s_U%s_N%s_dmu%s_%s.dat'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),dmu,(0,-1))
        #filename_mps2='data/mps_'+suffix2
        if append:
            pls=loadtxt(fname)[newaxis,:,:]
        else:
            ket_bias=MPS.load(filename_mps)
            #ket_bias=1./sqrt(2)*(MPS.load(filename_mps2)-1j*ket_bias)
            #ket_bias.compress()
            pls=[dos4mps(spaceconfig=expander.spaceconfig,ket=ket) for ket in [ket_bias]]
            savetxt(fname,pls[0].real)

    #pls=sum(pls,axis=1)
    pls=array(pls)-0.5
    nsite=pls.shape[-1]
    pls_left=pls[:,:,:nsite/2]
    pls_right=pls[:,:,nsite/2:]
    print 'occupation in left block -> %s, right block -> %s.'%(sum(pls_left,axis=(-1,-2)),sum(pls_right,axis=(-1,-2)))
    if ONSV: return pls
    ion()
    lw=2
    lc='r'
    for n in xrange(len(pls)):
        pln=pls[n]
        ax=subplot(101+n+10*len(pls))
        for s in xrange(2):
            color='b' if s==0 else 'r'
            lc=LineCollection([[(i,0),(i,pln[s,i].real.item())] for i in xrange(model.nsite)])
            lc.set_linewidth(lw)
            lc.set_color(color)
            lc.set_linestyle('--' if s==1 else '-')
            ax.add_collection(lc)

        ax.autoscale()
        ax.margins(0.1)
        xlabel('N')
        ylabel(r'$\rho-\bar{\rho}$')
    pdb.set_trace()
开发者ID:GiggleLiu,项目名称:apps,代码行数:70,代码来源:views.py

示例9: ScatterLayerArtist

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linestyle [as 别名]

#.........这里部分代码省略.........
                        if self.state.size_mode == 'Fixed':
                            s = self.state.size * self.state.size_scaling
                            s = broadcast_to(s, self.scatter_artist.get_sizes().shape)
                        else:
                            s = self.layer[self.state.size_att].ravel()
                            s = ((s - self.state.size_vmin) /
                                 (self.state.size_vmax - self.state.size_vmin)) * 30
                            s *= self.state.size_scaling

                        # Note, we need to square here because for scatter, s is actually
                        # proportional to the marker area, not radius.
                        self.scatter_artist.set_sizes(s ** 2)

        if self.state.line_visible:

            if self.state.cmap_mode == 'Fixed':
                if force or 'color' in changed or 'cmap_mode' in changed:
                    self.line_collection.set_array(None)
                    self.line_collection.set_color(self.state.color)
            elif force or any(prop in changed for prop in CMAP_PROPERTIES):
                # Higher up we oversampled the points in the line so that
                # half a segment on either side of each point has the right
                # color, so we need to also oversample the color here.
                c = self.layer[self.state.cmap_att].ravel()
                cnew = np.zeros((len(c) - 1) * 2)
                cnew[::2] = c[:-1]
                cnew[1::2] = c[1:]
                set_mpl_artist_cmap(self.line_collection, cnew, self.state)

            if force or 'linewidth' in changed:
                self.line_collection.set_linewidth(self.state.linewidth)

            if force or 'linestyle' in changed:
                self.line_collection.set_linestyle(self.state.linestyle)

        if self.state.vector_visible and self.vector_artist is not None:

            if self.state.cmap_mode == 'Fixed':
                if force or 'color' in changed or 'cmap_mode' in changed:
                    self.vector_artist.set_array(None)
                    self.vector_artist.set_color(self.state.color)
            elif force or any(prop in changed for prop in CMAP_PROPERTIES):
                c = self.layer[self.state.cmap_att].ravel()
                set_mpl_artist_cmap(self.vector_artist, c, self.state)

        if self.state.xerr_visible or self.state.yerr_visible:

            for eartist in list(self.errorbar_artist[2]):

                if eartist is None:
                    continue

                if self.state.cmap_mode == 'Fixed':
                    if force or 'color' in changed or 'cmap_mode' in changed:
                        eartist.set_color(self.state.color)
                elif force or any(prop in changed for prop in CMAP_PROPERTIES):
                    c = self.layer[self.state.cmap_att].ravel()
                    set_mpl_artist_cmap(eartist, c, self.state)

                if force or 'alpha' in changed:
                    eartist.set_alpha(self.state.alpha)

                if force or 'visible' in changed:
                    eartist.set_visible(self.state.visible)

                if force or 'zorder' in changed:
开发者ID:stscieisenhamer,项目名称:glue,代码行数:70,代码来源:layer_artist.py


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