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


Python Rectangle.contains方法代码示例

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


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

示例1: RectROI

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

    def __init__(self, ax, fig, canvas, red=0.5, green=0.5, blue=0.5):

        ROI.__init__(self, ax, fig, canvas)

        self.x0 = 0
        self.y0 = 0
        self.x1 = 0
        self.y1 = 0
        self.line_color = (red, green, blue)
        self.rect = None
        return

    def button_press_callback(self, event):

        if event.inaxes:
            if event.button == 1:  # If you press the left mouse button
                if self.rect is None:
                    self.x0 = event.xdata
                    self.y0 = event.ydata
        return

    def button_release_callback(self, event):
        # When the user releases the mouse button, make sure the ROI line
        # no longer moves with the mouse.
        if event.button == 1:

            if self.rect is None:
                self.x1 = event.xdata
                self.y1 = event.ydata
                width = self.x1 - self.x0
                height = self.y1 - self.y0
                self.rect = Rectangle((self.x0, self.y0), width, height, color=self.line_color, fill=False, picker=True,
                                      visible=True, figure=self.fig)

                ax = event.inaxes
                ax.add_patch(self.rect)
                self.fig.canvas.draw()

        self.grab_line = None

        return

    def motion_notify_callback(self, event):
        '''
        This is called when the user moves the mouse over the plot.
        It will change the size or position of the ROI.
        '''

        if event.inaxes:
            if (event.button == 1) and (not (self.grab_line is None)):
                # Change the position of the bottom right corner of the ROI
                # as the mouse is dragged across the image.
                self.x1 = event.xdata
                self.y1 = event.ydata
                width = self.x1 - self.x0
                height = self.y1 - self.y0

                self.rect.set_width(width)
                self.rect.set_height(height)

                self.fig.canvas.draw()

            if (event.button == 3) and (not (self.grab_line is None)):
                # Change the position of the top left corner of the ROI
                # as the mouse is dragged across the image.
                self.x0 = event.xdata
                self.y0 = event.ydata

                self.rect.set_xy((self.x0, self.y0))

                self.fig.canvas.draw()

        return

    def object_picked_callback(self, event):
        # Set the line grabbed to the object that is clicked on.
        contains, attrd = self.rect.contains(event.mouseevent)
        if contains:
            self.grab_line = event.artist
        return

    def AddLines(self):
        if self.rect is not None:
            self.ax.add_patch(self.rect)
            self.ax.figure.canvas.draw()

        return

    def RemoveLines(self):
        try:
            self.rect.remove()
            self.fig.canvas.draw()
        except AttributeError:
            return
        return

    def GetDimensions(self):
        dim_list = []
#.........这里部分代码省略.........
开发者ID:roehrig,项目名称:XrayDiffractionDataTool,代码行数:103,代码来源:graphingtools.py


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