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


Python LineCollection.set_segments方法代码示例

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


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

示例1: __init__

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
class Tracks:
    def __init__(self, ax, stormcells):
        self.tracks = None
        self.update_trackmap(ax, stormcells)

    def update_trackmap(self, ax, stormcells):
        if self.tracks is not None:
            self.tracks.remove()
            self.tracks = None
        if self.tracks is None:
            self.tracks = LineCollection([])
            ax.add_collection(self.tracks)

        self.trackmap = []
        for trackid in range(np.max(stormcells['track_id']) + 1):
            indexes = np.where(stormcells['track_id'] == trackid)[0]
            # Makes sure the track segments are in chronological order
            indexes = indexes[np.argsort(stormcells['frame_index'][indexes])]
            self.trackmap.append(indexes)

    def update_frame(self, frame_index, stormcells):
        segments = []
        for trackid, indexes in enumerate(self.trackmap):
            trackdata = stormcells[indexes]
            trackdata = trackdata[trackdata['frame_index'] <= frame_index]
            segments.append(zip(trackdata['xcent'], trackdata['ycent'])
                            or [(np.nan, np.nan)])
        self.tracks.set_segments(segments)
开发者ID:dboyliao,项目名称:Learn_Matplotlib,代码行数:30,代码来源:plain_tracks.py

示例2: do_3d_projection

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
    def do_3d_projection(self, renderer):
        """
        Project the points according to renderer matrix.
        """
        xyslist = [
            proj3d.proj_trans_points(points, renderer.M) for points in
            self._segments3d]
        segments_2d = [np.column_stack([xs, ys]) for xs, ys, zs in xyslist]
        LineCollection.set_segments(self, segments_2d)

        # FIXME
        minz = 1e9
        for xs, ys, zs in xyslist:
            minz = min(minz, min(zs))
        return minz
开发者ID:magnunor,项目名称:matplotlib,代码行数:17,代码来源:art3d.py

示例3: Tracks

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
class Tracks(object):
    def __init__(self, ax, tails=None):
        self.tracks = None
        self.tails = tails
        self.initialize_lines(ax)

    @staticmethod
    def create_trackmap(stormdata):
        trackmap = []
        for trackid in range(np.max(stormdata['track_id']) + 1):
            indexes = np.where(stormdata['track_id'] == trackid)[0]
            # Makes sure the track segments are in chronological order
            indexes = indexes[np.argsort(stormdata['frame_index'][indexes])]
            trackmap.append(indexes)
        return trackmap

    def remove_lines(self):
        if self.tracks is not None:
            self.tracks.remove()
            self.tracks = None

    def initialize_lines(self, ax):
        self.remove_lines()
        self.tracks = LineCollection([])
        ax.add_collection(self.tracks)

    def update_lines(self, frame_index, stormdata):
        segments = []
        for indexes in self.create_trackmap(stormdata):
            trackdata = stormdata[indexes]
            trackdata = trackdata[trackdata['frame_index'] <= frame_index]
            if self.tails:
                mask = trackdata['frame_index'] >= (frame_index - self.tails)
                trackdata = trackdata[mask]
            # There must always be something in a track, even it it is NaNs.
            segments.append(zip(trackdata['xcent'], trackdata['ycent'])
                            or [(np.nan, np.nan)])
        self.tracks.set_segments(segments)

    def lolite_line(self, indx):
        self.hilite_line(indx, 1)

    def hilite_line(self, indx, lw=4):
        if indx is not None:
            lws = self.tracks.get_linewidths()
            lws[indx] = lw
            self.tracks.set_linewidths(lws)
开发者ID:dboyliao,项目名称:Learn_Matplotlib,代码行数:49,代码来源:track_tails.py

示例4: ScatterPlot

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
class ScatterPlot(object):
    def __init__(self, feeder, marker = 'o'):
        self.marker = marker
        self.feeder = feeder
        self.stream = iter(self.feeder)

    def get_frames_len(self):
        return len(self.feeder.time_intervals) - 1

    def get_frame(self):
        return self.feeder.frame

    def get_limits(self):
        return self.feeder.get_limits()

    def setup_plot(self):
        x, y, c = next(self.stream)
        ax = plt.gca()
        self.scat = ax.scatter(x, y, c = c, marker = self.marker, s = 25)
        return self.scat

    def setup_plot_edges(self):
        lines = self.feeder.get_current_edges()
        ax = plt.gca()
        self.lines = LineCollection(lines, linewidths=0.1)
        ax.add_collection(self.lines)

    def update_edges(self):
        lines = self.feeder.get_current_edges()
        self.lines.set_segments(lines)

    def prev_state(self):
        self.feeder.prev()
        self.stream = iter(self.feeder)

    def update_plot(self):
        x, y, _ = next(self.stream)
        new_data = np.array(zip(x, y))
        self.scat.set_offsets(new_data)
        return self.scat
开发者ID:DSRC-GPU,项目名称:Gephi-ForceAtlas2,代码行数:42,代码来源:animator.py

示例5: set_segments

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
 def set_segments(self, segments):
     '''
     Set 3D segments
     '''
     self._segments3d = np.asanyarray(segments)
     LineCollection.set_segments(self, [])
开发者ID:Aharobot,项目名称:matplotlib,代码行数:8,代码来源:art3d.py

示例6: set_segments

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
 def set_segments(self, segments):
     '''
     Set 3D segments
     '''
     self._segments3d = segments
     LineCollection.set_segments(self, [])
开发者ID:CTPUG,项目名称:matplotlib-py3,代码行数:8,代码来源:art3d.py

示例7: set_segments

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
 def set_segments(self, segments):
     """
     Set 3D segments.
     """
     self._segments3d = np.asanyarray(segments)
     LineCollection.set_segments(self, [])
开发者ID:magnunor,项目名称:matplotlib,代码行数:8,代码来源:art3d.py

示例8: HoughDemo

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

#.........这里部分代码省略.........
                label=u"直线检测"
            ),
            Group(
                Item("dp", label=u"分辨率(像素)"),
                Item("mindist", label=u"圆心最小距离(像素)"),
                Item("param2", label=u"圆心检查阈值"),
                Item("min_radius", label=u"最小半径"),
                Item("max_radius", label=u"最大半径"),
                label=u"圆检测"
            ),
            Group(
                Item("linewidth", label=u"线宽"),
                Item("alpha", label=u"alpha"),
                HGroup(
                    Item("check_line", label=u"直线"),
                    Item("check_circle", label=u"圆"),
                ),
                label=u"绘图参数"
            )
        )

    def __init__(self, **kwargs):
        super(HoughDemo, self).__init__(**kwargs)
        self.connect_dirty("th2, show_canny, show_blur, rho, theta, hough_th,"
                            "min_radius, max_radius, blur_sigma,"
                           "minlen, maxgap, dp, mindist, param2, "
                           "linewidth, alpha, check_line, check_circle")
        self.lines = LineCollection([], linewidths=2, alpha=0.6)
        self.axe.add_collection(self.lines)

        self.circles = EllipseCollection(
            [], [], [],
            units="xy",
            facecolors="none",
            edgecolors="red",
            linewidths=2,
            alpha=0.6,
            transOffset=self.axe.transData)

        self.axe.add_collection(self.circles)

    def _img_changed(self):
        self.img_gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)

    def draw(self):
        img_smooth = cv2.GaussianBlur(self.img_gray, (0, 0), self.blur_sigma, self.blur_sigma)
        img_edge = cv2.Canny(img_smooth, self.th2 * 0.5, self.th2)

        if self.show_blur and self.show_canny:
            show_img = cv2.cvtColor(np.maximum(img_smooth, img_edge), cv2.COLOR_BAYER_BG2BGR)
        elif self.show_blur:
            show_img = cv2.cvtColor(img_smooth, cv2.COLOR_BAYER_BG2BGR)
        elif self.show_canny:
            show_img = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2BGR)
        else:
            show_img = self.img

        if self.check_line:
            theta = self.theta / 180.0 * np.pi
            lines = cv2.HoughLinesP(img_edge,
                                    self.rho, theta, self.hough_th,
                                    minLineLength=self.minlen,
                                    maxLineGap=self.maxgap)

            if lines is not None:
                lines = lines[0]
                lines.shape = -1, 2, 2
                self.lines.set_segments(lines)
                self.lines.set_visible(True)
            else:
                self.lines.set_visible(False)
        else:
            self.lines.set_visible(False)

        if self.check_circle:
            circles = cv2.HoughCircles(img_smooth, 3,
                                       self.dp, self.mindist,
                                       param1=self.th2,
                                       param2=self.param2,
                                       minRadius=self.min_radius,
                                       maxRadius=self.max_radius)

            if circles is not None:
                circles = circles[0]
                self.circles._heights = self.circles._widths = circles[:, 2]
                self.circles.set_offsets(circles[:, :2])
                self.circles._angles = np.zeros(len(circles))
                self.circles._transOffset = self.axe.transData
                self.circles.set_visible(True)
            else:
                self.circles.set_visible(False)
        else:
            self.circles.set_visible(False)

        self.lines.set_linewidths(self.linewidth)
        self.circles.set_linewidths(self.linewidth)
        self.lines.set_alpha(self.alpha)
        self.circles.set_alpha(self.alpha)

        self.draw_image(show_img)
开发者ID:Andor-Z,项目名称:scpy2,代码行数:104,代码来源:hough_demo.py

示例9: SURFDemo

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

#.........这里部分代码省略.........
    hessian_threshold = Int(2000)
    n_octaves = Int(2)

    poly = Instance(PolygonWidget)

    def control_panel(self):
        return VGroup(
            Item("m_perspective", label=u"变换矩阵", editor=ArrayEditor(format_str="%g")),
            Item("m_perspective2", label=u"变换矩阵", editor=ArrayEditor(format_str="%g")),
            Item("hessian_threshold", label=u"hessianThreshold"),
            Item("n_octaves", label=u"nOctaves")
        )

    def __init__(self, **kwargs):
        super(SURFDemo, self).__init__(**kwargs)
        self.poly = None
        self.init_points = None
        self.lines = LineCollection([], linewidths=1, alpha=0.6, color="red")
        self.axe.add_collection(self.lines)
        self.connect_dirty("poly.changed,hessian_threshold,n_octaves")

    def init_poly(self):
        if self.poly is None:
            return
        h, w, _ = self.img_color.shape
        self.init_points = np.array([(w, 0), (2*w, 0), (2*w, h), (w, h)], np.float32)
        self.poly.set_points(self.init_points)
        self.poly.update()

    def init_draw(self):
        style = {"marker": "o"}
        self.poly = PolygonWidget(axe=self.axe, points=np.zeros((3, 2)), style=style)
        self.init_poly()

    @on_trait_change("hessian_threshold, n_octaves")
    def calc_surf1(self):
        self.surf = cv2.SURF(self.hessian_threshold, self.n_octaves)
        self.key_points1, self.features1 = self.surf.detectAndCompute(self.img_gray, None)
        self.key_positions1 = np.array([kp.pt for kp in self.key_points1])

    def _img_changed(self):
        self.img_gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)
        self.img_color = cv2.cvtColor(self.img_gray, cv2.COLOR_GRAY2RGB)
        self.img_show = np.concatenate([self.img_color, self.img_color], axis=1)
        self.size = self.img_color.shape[1], self.img_color.shape[0]
        self.calc_surf1()

        FLANN_INDEX_KDTREE = 1
        index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
        search_params = dict(checks=100)

        self.matcher = cv2.FlannBasedMatcher(index_params, search_params)

        self.init_poly()

    def settings_loaded(self):
        src = self.init_points.copy()
        w, h = self.size
        src[:, 0] -= w
        dst = cv2.perspectiveTransform(src[None, :, :], self.m_perspective)
        dst = dst.squeeze()
        dst[:, 0] += w
        self.poly.set_points(dst)
        self.poly.update()

    def draw(self):
        if self.poly is None:
            return
        w, h = self.size
        src = self.init_points.copy()
        dst = self.poly.points.copy().astype(np.float32)
        src[:, 0] -= w
        dst[:, 0] -= w
        m = cv2.getPerspectiveTransform(src, dst)
        self.m_perspective = m
        img2 = cv2.warpPerspective(self.img_gray, m, self.size, borderValue=[255]*4)
        self.img_show[:, w:, :] = img2[:, :, None]
        key_points2, features2 = self.surf.detectAndCompute(img2, None)

        key_positions2 = np.array([kp.pt for kp in key_points2])

        match_list = self.matcher.knnMatch(self.features1, features2, k=1)
        index1 = np.array([m[0].queryIdx for m in match_list])
        index2 = np.array([m[0].trainIdx for m in match_list])

        distances = np.array([m[0].distance for m in match_list])

        n = min(50, len(distances))
        best_index = np.argsort(distances)[:n]
        matched_positions1 = self.key_positions1[index1[best_index]]
        matched_positions2 = key_positions2[index2[best_index]]

        self.m_perspective2, mask = cv2.findHomography(matched_positions1, matched_positions2, cv2.RANSAC)

        lines = np.concatenate([matched_positions1, matched_positions2], axis=1)
        lines[:, 2] += w
        line_colors = COLORS[mask.ravel()]
        self.lines.set_segments(lines.reshape(-1, 2, 2))
        self.lines.set_color(line_colors)
        self.draw_image(self.img_show)
开发者ID:Andor-Z,项目名称:scpy2,代码行数:104,代码来源:surf_demo.py

示例10: SpikeBrowserUI

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

#.........这里部分代码省略.........
        self.i_min = 0
        self.i_max = n_pts - self.i_window
        self.n_chans = n_chans


        self.window.set_scroll_max(self.i_max, self.i_window)
    

        # Indices of data interval to be plotted:
        
        self.i_end = self.i_start + self.i_window
        
        
        self.time = np.arange(self.i_start,self.i_end)*1./self.FS
        
        self.segs = np.empty((n_chans, self.i_window, 2))
        self.segs[:,:,0] = self.time[np.newaxis,:]
        self.segs[:,:,1] = self.x[:,self.i_start:self.i_end]
         
        ylims = (self.segs[:,:,1].min(), self.segs[:,:,1].max())
        offset = ylims[1]-ylims[0]
        self.offsets = np.arange(n_chans)*offset
        self.segs[:,:,1] += self.offsets[:,np.newaxis]
        
        self.ylims = np.array(ylims)
        
        if self.line_collection:
            self.line_collection.remove()

        self.line_collection = LineCollection(self.segs,
                                              offsets=None,
                                              transform=self.axes.transData,
                                              color='k')

        self.axes.add_collection(self.line_collection)
        self.axes.set_xlim((self.time[0], self.time[-1]))
        self.axes.set_ylim((self.ylims[0]+self.offsets.min(), 
                            self.ylims[1]+self.offsets.max()))

        self.canvas.draw()

    def draw_plot(self):

        self.time = np.arange(self.i_start,self.i_end)*1./self.FS
        self.segs[:,:,0] = self.time[np.newaxis,:]
        self.segs[:,:,1] = self.x[:,self.i_start:self.i_end]+self.offsets[:,np.newaxis]
        self.line_collection.set_segments(self.segs)

        # Adjust plot limits:
        self.axes.set_xlim((self.time[0], self.time[-1]))
        self.axes.set_ylim((self.ylims[0]+self.offsets.min(), 
                            self.ylims[1]+self.offsets.max()))
        
        if self.spt is not None:
            self.draw_spikes()
        # Redraw:                  
        self.canvas.draw()
        
    def draw_spikes(self):
        if self.spike_collection is not None:
            self.spike_collection.remove()
            self.spike_collection = None
        sp_win = self.sp_win 
        time = self.segs[0,:,0]*1000.
        t_min, t_max = time[0]-sp_win[0], time[-1]-sp_win[1]
        spt = self.spt[(self.spt>t_min) & (self.spt<t_max)]
        if len(spt)>0:
            n_pts = int((sp_win[1]-sp_win[0])/1000.*self.FS)
            sp_segs = np.empty((len(spt), self.n_chans, n_pts, 2))
            for i in range(len(spt)):
                start, = np.nonzero(time>=(spt[i]+sp_win[0]))
                start = start[0]
                stop  = start+n_pts
                sp_segs[i,:,:,0] = (time[np.newaxis,start:stop]/1000.)
                sp_segs[i,:,:,1] = self.segs[:, start:stop, 1]
            sp_segs = sp_segs.reshape(-1, n_pts, 2)
            if self.labels is not None:
                labs = self.labels[(self.spt>t_min) & (self.spt<t_max)]
                colors = np.repeat(self.color_func(labs), self.n_chans, 0)
            else:
                colors = 'r'
            self.spike_collection = LineCollection(sp_segs,
                                                  offsets=None,
                                                  color=colors,
                                                  transform=self.axes.transData)
            self.axes.add_collection(self.spike_collection)
            
        
    def OnScrollEvt(self, pos):

        # Update the indices of the plot:
        self.i_start = self.i_min + pos
        self.i_end = self.i_min + self.i_window + pos
        t_center = (self.i_start+self.i_window/2.)*1000./self.FS
        idx, = np.where(self.spt<t_center)
        if len(idx)>0:
            self.i_spike = idx[-1]
        else:
            self.i_spike = 0
        self.draw_plot()
开发者ID:belevtsoff,项目名称:SpikeSort,代码行数:104,代码来源:spike_browser.py

示例11: ScatterLayerArtist

# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_segments [as 别名]
class ScatterLayerArtist(MatplotlibLayerArtist):

    _layer_state_cls = ScatterLayerState

    def __init__(self, axes, viewer_state, layer_state=None, layer=None):

        super(ScatterLayerArtist, self).__init__(axes, viewer_state,
                                                 layer_state=layer_state, layer=layer)

        # Watch for changes in the viewer state which would require the
        # layers to be redrawn
        self._viewer_state.add_global_callback(self._update_scatter)
        self.state.add_global_callback(self._update_scatter)

        # Scatter
        self.scatter_artist = self.axes.scatter([], [])
        self.plot_artist = self.axes.plot([], [], 'o', mec='none')[0]
        self.errorbar_artist = self.axes.errorbar([], [], fmt='none')
        self.vector_artist = None
        self.line_collection = LineCollection(np.zeros((0, 2, 2)))
        self.axes.add_collection(self.line_collection)

        # Scatter density
        self.density_auto_limits = DensityMapLimits()
        self.density_artist = ScatterDensityArtist(self.axes, [], [], color='white',
                                                   vmin=self.density_auto_limits.min,
                                                   vmax=self.density_auto_limits.max)
        self.axes.add_artist(self.density_artist)

        self.mpl_artists = [self.scatter_artist, self.plot_artist,
                            self.errorbar_artist, self.vector_artist,
                            self.line_collection, self.density_artist]
        self.errorbar_index = 2
        self.vector_index = 3

        self.reset_cache()

    def reset_cache(self):
        self._last_viewer_state = {}
        self._last_layer_state = {}

    @defer_draw
    def _update_data(self, changed):

        # Layer artist has been cleared already
        if len(self.mpl_artists) == 0:
            return

        try:
            x = self.layer[self._viewer_state.x_att].ravel()
        except (IncompatibleAttribute, IndexError):
            # The following includes a call to self.clear()
            self.disable_invalid_attributes(self._viewer_state.x_att)
            return
        else:
            self.enable()

        try:
            y = self.layer[self._viewer_state.y_att].ravel()
        except (IncompatibleAttribute, IndexError):
            # The following includes a call to self.clear()
            self.disable_invalid_attributes(self._viewer_state.y_att)
            return
        else:
            self.enable()

        if self.state.markers_visible:
            if self.state.density_map:
                self.density_artist.set_xy(x, y)
                self.plot_artist.set_data([], [])
                self.scatter_artist.set_offsets(np.zeros((0, 2)))
            else:
                if self.state.cmap_mode == 'Fixed' and self.state.size_mode == 'Fixed':
                    # In this case we use Matplotlib's plot function because it has much
                    # better performance than scatter.
                    self.plot_artist.set_data(x, y)
                    self.scatter_artist.set_offsets(np.zeros((0, 2)))
                    self.density_artist.set_xy([], [])
                else:
                    self.plot_artist.set_data([], [])
                    offsets = np.vstack((x, y)).transpose()
                    self.scatter_artist.set_offsets(offsets)
                    self.density_artist.set_xy([], [])
        else:
            self.plot_artist.set_data([], [])
            self.scatter_artist.set_offsets(np.zeros((0, 2)))
            self.density_artist.set_xy([], [])

        if self.state.line_visible:
            if self.state.cmap_mode == 'Fixed':
                points = np.array([x, y]).transpose()
                self.line_collection.set_segments([points])
            else:
                # In the case where we want to color the line, we need to over
                # sample the line by a factor of two so that we can assign the
                # correct colors to segments - if we didn't do this, then
                # segments on one side of a point would be a different color
                # from the other side. With oversampling, we can have half a
                # segment on either side of a point be the same color as a
                # point
#.........这里部分代码省略.........
开发者ID:stscieisenhamer,项目名称:glue,代码行数:103,代码来源:layer_artist.py

示例12: SpikeBrowserUI

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

#.........这里部分代码省略.........
        self.window.set_scroll_max(self.i_max, self.i_window)

        # Indices of data interval to be plotted:
        self.i_end = self.i_start + self.i_window
        curr_slice = self.x[:, self.i_start:self.i_end]
        ylims = (curr_slice.min(), curr_slice.max())
        offset = ylims[1] - ylims[0]

        self.ylims = np.array(ylims)
        self.offsets = np.arange(n_chans) * offset
        
        # will be filled in draw_plot
        self.segs = np.empty((n_chans, self.i_window, 2))

        if self.line_collection:
            self.line_collection.remove()

        self.line_collection = LineCollection(self.segs,
                                              offsets=None,
                                              transform=self.axes.transData,
                                              color='k')

        self.axes.add_collection(self.line_collection)
        self.fancyyaxis.reset()

        self.draw_plot()

    def draw_plot(self):
        self.time = np.arange(self.i_start, self.i_end) * 1. / self.FS
        self.segs[:, :, 0] = self.time[np.newaxis, :]
        y_signal = self.x[:, self.i_start:self.i_end]
        y_signal = y_signal - np.mean(y_signal, 1)[:, None]
        self.segs[:, :, 1] = y_signal + self.offsets[:, np.newaxis]
        self.line_collection.set_segments(self.segs)

        # Adjust plot limits:
        self.axes.set_xlim((self.time[0], self.time[-1]))

        ygap = np.max(np.abs(self.ylims))
        self.axes.set_ylim((- ygap + self.offsets.min(),
                            ygap + self.offsets.max()))
        self.fancyyaxis.update()

        if self.spt is not None:
            self.draw_spikes()
        # Redraw:
        self.canvas.draw()


    def draw_spikes(self):
        if self.spike_collection is not None:
            self.spike_collection.remove()
            self.spike_collection = None
        sp_win = self.sp_win
        time = self.segs[0, :, 0] * 1000.
        t_min, t_max = time[0] - sp_win[0], time[-1] - sp_win[1]
        spt = self.spt[(self.spt > t_min) & (self.spt < t_max)]
        if len(spt) > 0:
            n_pts = int((sp_win[1] - sp_win[0]) / 1000. * self.FS)
            sp_segs = np.empty((len(spt), self.n_chans, n_pts, 2))
            for i in range(len(spt)):
                start, = np.nonzero(time >= (spt[i] + sp_win[0]))
                start = start[0]
                stop = start + n_pts
                sp_segs[i, :, :, 0] = (time[np.newaxis, start:stop] / 1000.)
                sp_segs[i, :, :, 1] = self.segs[:, start:stop, 1]
开发者ID:btel,项目名称:SpikeSort,代码行数:70,代码来源:spike_browser.py


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