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


Python Rectangle.set_axes方法代码示例

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


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

示例1: DataPicker

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_axes [as 别名]
class DataPicker(object):
    """Allows for brushing of flowers.csv data set """
    def __init__(self, figure, axis=None, tab=None, catNames=None, flowerColor=None):
        self.x1, self.y1=[],[]
        self.x2, self.y2=[],[]
        self.reset=[]
        self.patch=[]
        self.tab=tab
        self.catNames=catNames
        self.flowerColor=flowerColor
        self.textListSt=np.copy(textList)
        # Connect figure to events
        self.cidclick = figure.canvas.mpl_connect('button_press_event', self)
        self.cidrelease = figure.canvas.mpl_connect('button_release_event', self.on_release)
        self.keypress=figure.canvas.mpl_connect('key_press_event', self.onpress)
        if axis is None:
            axis = figure.axes[0]
        self.axis=axis
        self.figure=figure
        self.rect = Rectangle((0,0), 1, 1)

    def __call__(self, event):
        # Get first set of x and y values 
        self.x1, self.y1 = event.xdata, event.ydata
        # Get axis location of the mouse
        self.axis=event.inaxes
        # make sure the rectangle drawn in that subplot
        self.rect.set_axes(event.inaxes)
        # 0,0 = bottom

    def on_release(self, event):
        if event.inaxes != self.axis:
            return
        # If rectangle is still present, remove it
        if self.patch !=[] and self.reset !=[]: self.patch.remove() 
        newtab=[]
        # Get second set of x and y values
        self.x2, self.y2=event.xdata, event.ydata
        # Calculate rectangle width and height
        rectWidth=self.x2-self.x1
        rectHeight=self.y2-self.y1
        # Make a new rectangle
        self.rect=Rectangle((self.x1, self.y1), rectWidth, rectHeight, color='.75', alpha=.5)
        # Add a new rectangle to the axis
        self.patch=self.axis.add_patch(self.rect)
        self.reset=1
        # Find indices in rectangle, set those indices to NullFlow in data
        datCopy=np.copy(self.tab)
        newtab=findPoints(self.axis, self.x1, self.y1, self.x2, self.y2, datCopy, self.catNames)
        # Draw a new scatter plot with indices outside of the rectangle grayed out
        drawScatter(self.axis, newtab, self.catNames, self.flowerColor)
        self.axis.figure.canvas.draw()

    def onpress(self, event):
        # Quit if the user hits 'q'
        if event.key in ('q','Q'): plt.close(); 
        # Remove the rectangle if the user hits 'd'
        if event.key in ('d','D'):
            drawScatter(self.axis, self.tab, self.catNames, self.flowerColor)
            if self.patch !=[]: self.patch.remove()
            self.reset=[]
开发者ID:alinal,项目名称:AY250_HW,代码行数:63,代码来源:hw3_c.py


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