本文整理汇总了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=[]