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


Python Ellipse.remove方法代码示例

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


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

示例1: main

# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import remove [as 别名]

#.........这里部分代码省略.........
    # Reconstruct from distributions alone
    pi_opt = pi_maximize(noisy_emissions, dists)
    phi = np.empty((num_data, num_comps))
    for c in range(num_comps):
        phi[:,c] = dists[c].density(noisy_emissions)
    phi = np.matrix(phi)
    for i, pi in enumerate(pi_opt):
        phi[:,i] *= pi
    gamma_dists = phi / np.sum(phi, axis = 1)
    rec_dists = np.array(np.dot(gamma_dists, means))
    im_dists = image_from_array(rec_dists)
    summary.paste(im_dists, (30 + width, 40 + height))

    # Show summary image
    if show_summary:
        summary.show()
    summary.save('image_test_color_reconstruction.png')

    # Compare RMSE between reconstructions
    def rmse(x):
        return np.sqrt(np.mean((x - real_emissions) ** 2))
    print 'Raw MSE: %.1f' % rmse(noisy_emissions)
    print 'Blocked Gamma MSE: %.1f' % rmse(rec_blocked_gamma)
    print 'Dists MSE: %.1f' % rmse(rec_dists)

    # Visualize variance components
    if do_variance_viz:
        temp_files = []
        col = { 'R': 0, 'G': 1, 'B': 2 }
        fig = plt.figure()
        for i, (d, c1, c2) in enumerate([(real_emissions, 'R', 'G'),
                                         (real_emissions, 'R', 'B'),
                                         (real_emissions, 'G', 'B'),
                                         (noisy_emissions, 'R', 'G'),
                                         (noisy_emissions, 'R', 'B'),
                                         (noisy_emissions, 'G', 'B')]):
            ax = fig.add_subplot(2, 3, i+1)
            plt.hexbin(d[:,col[c1]], d[:,col[c2]], gridsize=30,
                       extent = (0, 255, 0, 255))
            plt.xlabel(c1)
            plt.ylabel(c2)
            plt.axis([-20, 275, -20, 275])
        for idx, dists in enumerate(dists_trace):
            ells = []
            for i, (d, c1, c2) in enumerate([(real_emissions, 'R', 'G'),
                                             (real_emissions, 'R', 'B'),
                                             (real_emissions, 'G', 'B'),
                                             (noisy_emissions, 'R', 'G'),
                                             (noisy_emissions, 'R', 'B'),
                                             (noisy_emissions, 'G', 'B')]):
                for dist in dists:
                    m, c = dist.mean(), dist.cov()
                    cm = (c[[col[c1], col[c2]]])[:,[col[c1], col[c2]]]
                    e, v = la.eigh(cm)
                    ell = Ellipse(xy = [m[col[c1]], m[col[c2]]],
                                  width = np.sqrt(e[0]),
                                  height = np.sqrt(e[1]),
                                  angle = (180.0 / np.pi) * np.arccos(v[0,0]))
                    ells.append(ell)
                    ax = fig.add_subplot(2, 3, i+1)
                    ax.add_artist(ell)
                    ell.set_clip_box(ax.bbox)
                    ell.set_alpha(0.9)
                    ell.set_facecolor(np.fmax(np.fmin(m / 255, 1), 0))
            file_name = 'tmp_%03d.png' % idx
            temp_files.append(file_name)
            plt.savefig(file_name, dpi = 100)
            for ell in ells:
                ell.remove()
        command = ('mencoder',
                   'mf://tmp_*.png',
                   '-mf',
                   'type=png:w=800:h=600:fps=5',
                   '-ovc',
                   'lavc',
                   '-lavcopts',
                   'vcodec=mpeg4',
                   '-oac',
                   'copy',
                   '-o',
                   'image_test_color_components.avi')
        os.spawnvp(os.P_WAIT, 'mencoder', command)
        for temp_file in temp_files:
            os.unlink(temp_file)

    # Find common variance components
    print 'True noise:'
    print cov
    chols = [la.cholesky(c) for c in covs]
    chol_recon = np.zeros((3,3))
    for i in range(3):
        for j in range(3):
            if j > i: continue
            chol_recon[i,j] = np.Inf
            for chol in chols:
                if abs(chol[i,j]) < abs(chol_recon[i,j]):
                    chol_recon[i,j] = chol[i,j]
    cov_recon = np.dot(chol_recon, np.transpose(chol_recon))
    print 'Reconstructed noise:'
    print cov_recon
开发者ID:othercriteria,项目名称:blocked_inference,代码行数:104,代码来源:image_test_color.py

示例2: ROIellipse

# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import remove [as 别名]
class ROIellipse(ROIcircle):      
    def __getstate__(self):
        return {'im':self.im, 'circle':(self.center, self.width, self.height), 'color': self.color}

    def __setstate__(self, d):
        self.im = d['im']
        self.center, self.width, self.height = d['circle']
        self.circ = Ellipse(*d['circle'], facecolor='none', edgecolor=self.color)
        self.color = self.color
        self.patch = None
        
    def draw(self, axes, figure, color):
        mycirc = Ellipse(self.center, self.width, self.height, facecolor='none', edgecolor=color)
        mycirc.set_linewidth(1)
        mycirc.set_alpha(1)
        mycirc.set_facecolor('none')
        mycirc.set_hatch('//')
        circ = axes.add_artist(mycirc)
        figure.canvas.draw()
        return circ

    def motion_notify_callback(self, event):
        """Draw a line from the last selected point to current pointer
        position. If left button is held, add points to the coords list
        at each movement.
        """
        if event.inaxes: 
            x, y = event.xdata, event.ydata
            
            if event.button == None and self.circ is not None: # Move line around 
                x0, y0 = self.circ.center
                self.circ.height = abs(y-y0)*2
                self.circ.width = abs(x-x0)*2
                self.fig.canvas.draw()
    
    def button_press_callback(self, event):
        """Left button: add point; middle button: delete point;
        right button: fill polygon and stop interaction.
        """
        if event.inaxes: 
            x, y = event.xdata, event.ydata
            ax = event.inaxes
            
            if event.button == 1:  # If you press the left button
                if self.circ == None: 
                    self.circ = Ellipse((x, y), 0.5, 0.5, facecolor='none', edgecolor=self.color)
                    self.center = x, y                    
                    ax.add_artist(self.circ)
                else: 
                    self.circ.set_color(self.color)
                    self.circ.set_edgecolor(self.color)
                    self.circ.set_facecolor('none')
                    self.circ.set_linewidth(1)
                    self.circ.set_alpha(1)
                    self.circ.set_hatch('//')
                    self.disconnect()
                    
                    self.height = self.circ.height
                    self.width = self.circ.width
                    self.completion_callback()
            elif event.button == 3 and self.circ is not None: # middle button: remove last segment
                self.circ.remove()                
                self.circ = None
            self.fig.canvas.draw()

    def get_coords(self):
        """Returns the x,y coordinates of that have been selected
        so far."""
        if not self.center:
            raise ValueError("cannot get ellipse coordinates before the dimensions are defined")
        
        return self.center, self.width, self.height

    def get_indices(self):
        """Returns a set of points that lie inside the picked polygon."""
        if not self.center:
            raise ValueError("Cannot get ellipse indices before the dimensions are defined")
        
        x, y = self.center
        w = self.width
        h = self.height
        return ellipse(y, x, h/2., w/2., self.im)
开发者ID:JoshBradshaw,项目名称:bloodtools,代码行数:84,代码来源:ROI.py


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