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


Python Rectangle.set_bounds方法代码示例

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


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

示例1: Alignment

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_bounds [as 别名]
class Alignment(Axes):
    """
    matplotlib.axes.Axes subclass for rendering sequence alignments.
    """
    def __init__(self, fig, rect, *args, **kwargs):
        self.aln = kwargs.pop("aln")
        nrows = len(self.aln)
        ncols = self.aln.get_alignment_length()
        self.alnidx = numpy.arange(ncols)
        self.app = kwargs.pop("app", None)
        self.showy = kwargs.pop('showy', True)
        Axes.__init__(self, fig, rect, *args, **kwargs)
        rgb = mpl_colors.colorConverter.to_rgb
        gray = rgb('gray')
        d = defaultdict(lambda:gray)
        d["A"] = rgb("red")
        d["a"] = rgb("red")
        d["C"] = rgb("blue")
        d["c"] = rgb("blue")
        d["G"] = rgb("green")
        d["g"] = rgb("green")
        d["T"] = rgb("yellow")
        d["t"] = rgb("yellow")
        self.cmap = d
        self.selector = RectangleSelector(
            self, self.select_rectangle, useblit=True
            )
        def f(e):
            if e.button != 1: return True
            else: return RectangleSelector.ignore(self.selector, e)
        self.selector.ignore = f
        self.selected_rectangle = Rectangle(
            [0,0],0,0, facecolor='white', edgecolor='cyan', alpha=0.3
            )
        self.add_patch(self.selected_rectangle)
        self.highlight_find_collection = None

    def plot_aln(self):
        cmap = self.cmap
        self.ntax = len(self.aln); self.nchar = self.aln.get_alignment_length()
        a = numpy.array([ [ cmap[base] for base in x.seq ]
                          for x in self.aln ])
        self.array = a
        self.imshow(a, interpolation='nearest', aspect='auto', origin='lower')
        y = [ i+0.5 for i in xrange(self.ntax) ]
        labels = [ x.id for x in self.aln ]
        ## locator.bin_boundaries(1,ntax)
        ## locator.view_limits(1,ntax)
        if self.showy:
            locator = MaxNLocator(nbins=50, integer=True)
            self.yaxis.set_major_locator(locator)
            def fmt(x, pos=None):
                if x<0: return ""
                try: return labels[int(round(x))]
                except: pass
                return ""
            self.yaxis.set_major_formatter(FuncFormatter(fmt))
        else:
            self.yaxis.set_major_locator(NullLocator())
        
        return self

    def select_rectangle(self, e0, e1):
        x0, x1 = map(int, sorted((e0.xdata+0.5, e1.xdata+0.5)))
        y0, y1 = map(int, sorted((e0.ydata+0.5, e1.ydata+0.5)))
        self.selected_chars = (x0, x1)
        self.selected_taxa = (y0, y1)
        self.selected_rectangle.set_bounds(x0-0.5,y0-0.5,x1-x0+1,y1-y0+1)
        self.app.figure.canvas.draw_idle()

    def highlight_find(self, substr):
        if not substr:
            if self.highlight_find_collection:
                self.highlight_find_collection.remove()
                self.highlight_find_collection = None
            return
            
        N = len(substr)
        v = []
        for y, x in align.find(self.aln, substr):
            r = Rectangle(
                [x-0.5,y-0.5], N, 1,
                facecolor='cyan', edgecolor='cyan', alpha=0.7
                )
            v.append(r)
        if self.highlight_find_collection:
            self.highlight_find_collection.remove()
        c = PatchCollection(v, True)
        self.highlight_find_collection = self.add_collection(c)
        self.app.figure.canvas.draw_idle()

    def extract_selected(self):
        r0, r1 = self.selected_taxa
        c0, c1 = self.selected_chars
        return self.aln[r0:r1+1,c0:c1+1]

    def zoom_cxy(self, x=0.1, y=0.1, cx=None, cy=None):
        """
        Zoom the x and y axes in by the specified proportion of the
        current view, with a fixed data point (cx, cy)
#.........这里部分代码省略.........
开发者ID:ChriZiegler,项目名称:ivy,代码行数:103,代码来源:alignment.py

示例2: CustomToolbar

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_bounds [as 别名]
class CustomToolbar(NavToolbar):

    toolitems = NavToolbar.toolitems + (
        (None, None, None, None),
        ("ROI", "Select ROI", "selection", "_on_custom_select"),
    )

    def __init__(self, plotCanvas):
        # create the default toolbar
        NavToolbar.__init__(self, plotCanvas)
        self.selector = RectSelector(
            self.canvas.figure.axes[0], self.onSelect, button=[1, 3], minspanx=5, minspany=5  # don't use middle button
        )
        self.selector.set_active(True)
        self.ax = self.canvas.figure.axes[0]
        self.roi = None
        self.fixedSize = False
        if wx.Platform == "__WXMAC__":
            self.to_draw = Rectangle(
                (0, 0), 0, 1, visible=False, facecolor="yellow", edgecolor="black", alpha=0.5, fill=True
            )
            self.ax.add_patch(self.to_draw)
            self.background = None

    def _init_toolbar(self):
        self._parent = self.canvas.GetParent()

        self.wx_ids = {}
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.AddSeparator()
                continue
            self.wx_ids[text] = wx.NewId()
            try:
                bitmap = _load_bitmap(image_file + ".png")
            except IOError:
                bitmap = wx.Bitmap(image_file + ".png")
            if text in ["Pan", "Zoom", "ROI"]:
                self.AddCheckTool(self.wx_ids[text], bitmap, shortHelp=text, longHelp=tooltip_text)
            else:
                self.AddSimpleTool(self.wx_ids[text], bitmap, text, tooltip_text)
            bind(self, wx.EVT_TOOL, getattr(self, callback), id=self.wx_ids[text])

        self.ToggleTool(self.wx_ids["ROI"], True)
        self.Realize()

    def _set_markers(self):
        self.canvas.parentFrame.set_markers()

    def _update_view(self):
        NavToolbar._update_view(self)
        self._set_markers()
        # MacOS needs a forced draw to update plot
        if wx.Platform == "__WXMAC__":
            self.canvas.draw()

    def draw(self):
        self._set_markers()
        NavToolbar.draw(self)
        # MacOS needs a forced draw to update plot
        if wx.Platform == "__WXMAC__":
            self.canvas.draw()

    def zoom(self, ev):
        if wx.Platform == "__WXMAC__":
            self.ToggleTool(self.wx_ids["Zoom"], self.GetToolState(self.wx_ids["Zoom"]))
        NavToolbar.zoom(self, ev)

    def pan(self, ev):
        if wx.Platform == "__WXMAC__":
            self.ToggleTool(self.wx_ids["Pan"], self.GetToolState(self.wx_ids["Pan"]))
        NavToolbar.pan(self, ev)

    def press_zoom(self, ev):
        if wx.Platform == "__WXMAC__":
            self.update_background()
            self.to_draw.set_visible(True)
        NavToolbar.press_zoom(self, ev)

    def release_zoom(self, ev):
        if wx.Platform == "__WXMAC__":
            self.to_draw.set_visible(False)
        NavToolbar.release_zoom(self, ev)

    def draw_rubberband(self, event, x0, y0, x1, y1):
        # XOR does not work on MacOS ...
        if wx.Platform != "__WXMAC__":
            NavToolbar.draw_rubberband(self, event, x0, y0, x1, y1)
        else:
            if self.background is not None:
                self.canvas.restore_region(self.background)
            c0, c1 = self.ax.transData.inverted().transform([[x0, y0], [x1, y1]])
            l, b = c0
            r, t = c1
            self.to_draw.set_bounds(l, b, r - l, t - b)
            self.ax.draw_artist(self.to_draw)
            self.canvas.blit(self.ax.bbox)

    def update_background(self):
        """force an update of the background"""
#.........这里部分代码省略.........
开发者ID:jochym,项目名称:pointsel,代码行数:103,代码来源:pointsel.py

示例3: StatsPanel

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

#.........这里部分代码省略.........
        wrapper to update_stats_box to receive messages & translate them correctly
        """
        x0,x1,y0,y1 = [None]*4
        if msg['xrange'] is not None:
            x0,x1 = msg['xrange']
        if msg['yrange'] is not None:
            y0,y1 = msg['yrange']
        if msg['xrange'] is not None or msg['yrange'] is not None:
            self.update_stats_box(x0, y0, x1, y1)
        if msg['show_overplot'] is not None:
            if msg['show_overplot']:
                self.redraw_overplot_on_image()
            else:
                self.remove_overplot_on_image()
        send_to_stream(sys.stdout, ('set-stats-box-parameters-done', True))

    def update_stats_box(self, x0=None, y0=None, x1=None, y1=None):
        if x0 is None:
            x0 = self.stats_rect.get_x()
        if y0 is None:
            y0 = self.stats_rect.get_y()
        if x1 is None:
            x1 = self.stats_rect.get_x() + self.stats_rect.get_width()
        if y1 is None:
            y1 = self.stats_rect.get_y() + self.stats_rect.get_height()
        if x0 > x1:
            x0, x1 = x1, x0
        if y0 > y1:
            y0, y1 = y1, y0
        x0 = min(max(0, x0), self.ztv_frame.display_image.shape[1] - 1)
        y0 = min(max(0, y0), self.ztv_frame.display_image.shape[0] - 1)
        x1 = min(max(0, x1), self.ztv_frame.display_image.shape[1] - 1)
        y1 = min(max(0, y1), self.ztv_frame.display_image.shape[0] - 1)
        self.stats_rect.set_bounds(x0, y0, x1 - x0, y1 - y0)
        if self.hideshow_button.GetLabel() == 'Hide':  
            self.ztv_frame.primary_image_panel.figure.canvas.draw()
        self.update_stats()

    def remove_overplot_on_image(self):
        self.ztv_frame.primary_image_panel.remove_patch('stats_panel:stats_rect')
        self.hideshow_button.SetLabel(u"Show")

    def redraw_overplot_on_image(self):
        self.ztv_frame.primary_image_panel.add_patch('stats_panel:stats_rect', self.stats_rect)
        self.hideshow_button.SetLabel(u"Hide")        

    def on_hideshow_button(self, evt):
        if self.hideshow_button.GetLabel() == 'Hide':
            self.remove_overplot_on_image()
        else:
            self.redraw_overplot_on_image()

    def get_x0y0x1y1_from_stats_rect(self):
        x0 = self.stats_rect.get_x()
        y0 = self.stats_rect.get_y()
        x1 = x0 + self.stats_rect.get_width()
        y1 = y0 + self.stats_rect.get_height()
        return x0,y0,x1,y1
        
    def update_stats(self, msg=None):
        x0,y0,x1,y1 = self.get_x0y0x1y1_from_stats_rect()
        x0, y0 = int(np.round(x0)), int(np.round(y0))
        x1, y1 = int(np.round(x1)), int(np.round(y1))
        self.last_string_values['x0'] = str(int(x0))
        self.x0_textctrl.SetValue(self.last_string_values['x0'])
        self.last_string_values['y0'] = str(int(y0))
开发者ID:henryroe,项目名称:ztv,代码行数:70,代码来源:stats_panel.py


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