本文整理汇总了Python中matplotlib.patches.Rectangle.set_color方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_color方法的具体用法?Python Rectangle.set_color怎么用?Python Rectangle.set_color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_color方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Annotate
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_color [as 别名]
class Annotate(object):
def __init__(self, image,name):
self.img = image
self.imgname = name
self.i = 1
self.col = 'b' # deafult color for true positive label
self.ax = plt.gca()
# Initialize the Reactangle patch object with properties
self.rect = Rectangle((0,0), 1, 1, alpha = 1,ls = 'solid',fill = False, clip_on = True,color = self.col)
# Initialize two diagonally opposite co-ordinates of reactangle as None
self.xc = None
self.yc = None
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.sizeModifier = 2
self.w = 30.0
self.h = 40.0
self.qkey = None
self.objList = []
#self.centers
# The list that will store value of those two co-ordinates of
# all the patches for storing into the file later
self.xy = []
self.ax.add_patch(self.rect)
# Initialize mpl connect object
connect = self.ax.figure.canvas.mpl_connect
# Create objects that will handle user initiated events
# We are using three events
# First event is button press event (on left key click)-
# on which on_click function is called
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_click)
self.ax.figure.canvas.mpl_connect('close_event', self.handle_close)
# Second event to draw, in case a mistake in labelling is made,
# deleting the patch requires redrawing the original canvas
self.draw_cid = connect('draw_event', self.grab_background)
# Third event - key press event
# To change color of the patches when you want to switch between
# true postive and false postive labels
self.ax.figure.canvas.mpl_connect('key_press_event',self.colorChange)
def objCreation(self):
# The new reactangle object to use after blit function (clearing
# the canvas and removing rectangle objects)
self.rect = Rectangle((0,0), 1, 1, alpha = 1,ls = 'solid',fill = False, clip_on = True)
self.xc = None # x co-ordinate of patch center
self.yc = None # y co-ordinate of patch center
self.x0 = None # top left x co-ordinate of patch center
self.y0 = None # top left y co-ordinate of patch center
self.x1 = None # lower right y co-ordinate of patch center
self.y1 = None # lower right y co-ordinate of patch center
self.sizeModifier = 2 # The amount by which width/height will increase/decrease
self.w = 30.0 # Initial width
self.h = 40.0 # Initial height
# Aspect Ratio of 3/4
# Add the patch on the axes object of figure
self.ax.add_patch(self.rect)
def deletePrevious(self):
'''
Deletes the latest patch that was drawn
'''
# Clear the screen by calling blit function
self.blit()
# Remove the last patch co-ordinates from the list
self.xy = self.xy[:-1]
# Redraw all the rects except the previous ones
for coords in self.xy:
self.rect.set_width(coords[2] - coords[0])
self.rect.set_height(coords[3] - coords[1])
self.rect.set_xy((coords[0], coords[1]))
self.rect.set_color(coords[4])
self.ax.draw_artist(self.rect)
self.ax.figure.canvas.blit(self.ax.bbox)
def resize(self,det):
'''
Resizing at the same center, maintaing the same aspect ratio
and using key only (without dragging)
'''
# Resizing without dragging requires deleting previous patch
# Saving the center, width, height of the patch before deleting it
# As it will be used for reconstructing with increased/decreased size
last_obj = self.xy[-1]
# print last_obj
#.........这里部分代码省略.........
示例2: getRectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_color [as 别名]
def getRectangle(x, y, width, height, color, alpha=1):
rect = Rectangle((x, y), width, height)
rect.set_color(color)
rect.set_alpha(alpha)
return rect
示例3: Annotate
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_color [as 别名]
class Annotate(object):
def __init__(self, image,name, imgid):
self.img = image
self.imgname = name
self.imgid = imgid
self.i = 1
self.col = 'b' # deafult color for true positive label
self.ax = plt.gca()
# Initialize the Reactangle patch object with properties
self.rect = Rectangle((0,0), 1, 1, alpha = 1,ls = 'solid',fill = False, clip_on = True,color = self.col)
# Initialize two diagonally opposite co-ordinates of reactangle as None
self.xc = None
self.yc = None
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.height = None
self.width = None
self.mx0 = None
self.my0 = None
self.mx1 = None
self.my1 = None
self.sizeModifier = 2
self.w = 30.0
self.h = 40.0
self.qkey = None
#self.centers
# The list that will store value of those two co-ordinates of
# all the patches for storing into the file later
self.xy = []
self.ax.add_patch(self.rect)
# Initialize mpl connect object
connect = self.ax.figure.canvas.mpl_connect
# Create objects that will handle user initiated events
# We are using three events
# First event is button press event (on left key click)-
# on which on_click function is called
connect('button_press_event', self.on_click)
connect('close_event', self.handle_close)
# Second event to draw, in case a mistake in labelling is made,
# deleting the patch requires redrawing the original canvas
self.draw_cid = connect('draw_event', self.grab_background)
# Third event - key press event
# To change color of the patches when you want to switch between
# true postive and false postive labels
connect('key_press_event',self.colorChange)
def objCreation(self):
# The new reactangle object to use after blit function (clearing
# the canvas and removing rectangle objects)
self.rect = Rectangle((0,0), 1, 1, alpha = 1,ls = 'solid',fill = False, clip_on = True)
self.xc = None # x co-ordinate of patch center
self.yc = None # y co-ordinate of patch center
self.x0 = None # top left x co-ordinate of patch center
self.y0 = None # top left y co-ordinate of patch center
self.x1 = None # lower right y co-ordinate of patch center
self.y1 = None # lower right y co-ordinate of patch center
self.sizeModifier = 2 # The amount by which width/height will increase/decrease
self.w = 30.0 # Initial width
self.h = 40.0 # Initial height
# Aspect Ratio of 3/4
# Add the patch on the axes object of figure
self.ax.add_patch(self.rect)
def deletePrevious(self):
'''
Deletes the latest patch that was drawn
'''
# Clear the screen by calling blit function
self.blit()
# Remove the last patch co-ordinates from the list
self.xy = self.xy[:-1]
# Redraw all the rects except the previous ones
for coords in self.xy:
self.rect.set_width(coords[2] - coords[0])
self.rect.set_height(coords[3] - coords[1])
self.rect.set_xy((coords[0], coords[1]))
self.rect.set_color(coords[4])
self.ax.draw_artist(self.rect)
self.ax.figure.canvas.blit(self.ax.bbox)
def resize(self,det):
'''
Resizing at the same center, maintaing the same aspect ratio
and using key only (without dragging)
'''
#.........这里部分代码省略.........