本文整理汇总了Python中matplotlib.patches.Rectangle.get_xy方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.get_xy方法的具体用法?Python Rectangle.get_xy怎么用?Python Rectangle.get_xy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.get_xy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_rectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_xy [as 别名]
def draw_rectangle(self, lower, upper, node):
r = Rectangle(lower, upper[0] - lower[0], upper[1]-lower[1],
edgecolor='k',
facecolor = (0,0,0))
self.ax.add_patch(r)
if node.is_leaf():
rx, ry = r.get_xy()
cx = rx + r.get_width()/2.0
cy = ry + r.get_height()/2.0
r.set_facecolor( node.get_colour())
self.ax.annotate(node.get_weight(), (cx, cy), color=(0,0,0), fontsize = 10, ha='center', va='center')
print node.name, rx, ry, cx, cy
示例2: draw_rectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_xy [as 别名]
def draw_rectangle(self, lower, upper, node):
r = Rectangle( lower, upper[0]-lower[0], upper[1] - lower[1],
edgecolor='k',
facecolor= node.get_color(),
label=node.name)
self.ax.add_patch(r)
rx, ry = r.get_xy()
rw = r.get_width()
rh = r.get_height()
cx = rx + rw/2.0
cy = ry + rh/2.0
if isinstance(node, PathNode):
t = node.name
if rw * 3 < rh:
t += ", "
else:
t += "\n"
t += str(node.size) + ", " + node.stype
c='w'
if rw < rh:
o = "vertical"
else:
o = "horizontal"
else:
t = node.name
if node.isfile:
c='k'
o = 45
else:
return
self.ax.annotate(
t,
(cx,cy),
color=c,
weight='bold', ha='center', va='center',
rotation=o
)
示例3: handle_event
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_xy [as 别名]
def handle_event():
global command
global command_meta
global main_pic
global history
global patch
global patches
global click_handlers
global G
if command=="horizontal_line" or command=="vertical_line":
h,w = main_pic.shape[:2]
if patch is not None:
w1,h1 = patch.get_xy()
if command=="horizontal_line":
line = Line(0,int(h1),w,int(h1), int(patch.get_height()), magenta)
else:
line = Line(int(w1),0,int(w1),h, int(patch.get_width()), magenta)
main_pic = draw_line_on_picture(main_pic, line)
patch=None
else:
if command=="horizontal_line":
patch = Rectangle((0,0), w, 1, edgecolor='magenta', alpha=1)
else:
patch = Rectangle((0,0), 1, h, edgecolor='magenta', alpha=1)
if command=="needle" or command=="angle_needle":
G["needle"]["active"] = True
just_added_patch = False
if "pt1" in G["needle"] and "pt2" in G["needle"]:
if patch is None:
print "Drawing needle patch"
pt1 = G["needle"]["pt1"]
pt2 = G["needle"]["pt2"]
if command=="needle":
patch = Rectangle((pt1[0], pt1[1]), abs(pt2[0]-pt1[0]), abs(pt2[1]-pt1[1]), edgecolor='magenta', alpha=1, facecolor='magenta')
else:
patch = Polygon(np.array([pt1, pt2, p(pt1), p(pt2)]), closed=False,
edgecolor='magenta', alpha=1, facecolor='magenta')
angle = get_angle(pt1, pt2)
print ("Angle :{}".format(angle))
# how to add text?
just_added_patch = True
if patch is not None and not just_added_patch:
if isinstance(patch, Polygon):
patches.append(patch)
patch=None
else:
print "finalize"
w1,h1 = patch.get_xy()
w = patch.get_width()
h = patch.get_height()
if w>h:
print("horizontal patch")
line = Line(int(w1),int(h1),int(w1+w),int(h1), 3, magenta)
else:
line = Line(int(w1),int(h1),int(w1),int(h1+h), 3, magenta)
main_pic = draw_line_on_picture(main_pic, line)
G["needle"] = {}
if command == "divide":
divide(command_meta.xdata, command_meta.ydata)
if command == "brighten":
main_pic = do_brighten(main_pic)
if command == "mirror":
main_pic = np.fliplr(main_pic)
if command == "zoom":
click_handlers = not click_handlers
if command == "darken":
main_pic = do_darken(main_pic)
if command == "edge":
main_pic = edge_detect(main_pic)
if command == "resize_patch":
if patch is not None:
h = patch.get_height()
w = patch.get_width()
patch.set_width(int(w * 0.9))
patch.set_height(int(h * 0.9))
if command == "crop":
if patch is not None:
# apply patch
# crop main_pic
h = patch.get_height()
w = patch.get_width()
w1,h1 = patch.get_xy()
main_pic = main_pic[slice(h1,h1+h),slice(w1,w1+w),slice(None)]
patch=None
else:
# create patch
# TODO: can read this from settings :))
portrait_ratio = 14.8/20.8
if orientation=="portrait":
w_to_h = portrait_ratio
else:
#.........这里部分代码省略.........
示例4: InteractiveCanvas
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_xy [as 别名]
#.........这里部分代码省略.........
# Draw extant rectangles if applicable
if self.mplRectangles:
self.drawRectangles()
# Update the figure object/property
self.fig = plt.gcf()
self.fig.tight_layout()
def drawRectangles(self):
"""Adds rectangles to the plot if they are currently stored"""
# Iterate through the mpl Rectangles to draw them with the proper color
for i, rectangle in enumerate(self.rectCoordinates):
color = self.colors[i * 4]
xy, width, height = rectangle
rect = Rectangle(
xy, width, height, alpha=self.alpha, color=color)
self.ax.add_patch(rect)
def addPointsAndLine(self, xdata, ydata, color='#003366', draw=True):
"""Adds the points and a line to the figure
Parameters
----------
xdata: `np.array`
A flat numpy array of x values for the plot
ydata: `np.array`
A flat numpy array of y values for the plot
color: str
Hex code or other matplotlib accepted color key for the points/line
draw: bool
If True, the plot will be drawn. If False, it will not. Mainly a
product of the test code
"""
# Currently ydata is longer than xdata with schlumberger, so handle
# that if it makes it this far into the program
if len(xdata) != len(ydata):
if len(ydata) > len(xdata):
xdata = xdata[:len(ydata)]
else:
ydata = ydata[:len(xdata)]
# log/log plot of x and y data
plt.loglog(
xdata, ydata, linestyle=self.linestyle,
marker=self.marker, color=color)
# Draw the updates
if draw:
self.fig.tight_layout()
self.ax.figure.canvas.draw()
def onPress(self, event):
"""Handle mouse press events on the matplotlib figure cavas
Parameters
----------
event: matplotlib.event
The matplotlib event definition. In this case, a mouse click.
"""
self.x0 = event.xdata
self.y0 = event.ydata
def onRelease(self, event):
"""Handles release of mouse button events on the matplotlib canvas
Parameters
----------
event: matplotlib.event
The matplotlib event definition. In this case, a mouse release.
"""
try:
self.x1 = event.xdata
self.y1 = event.ydata
# Create a rectangle on the plot
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
# Store and return the rectangle attributes as a tuple
self.rectxy = (
self.rect.get_xy(), self.rect._width, self.rect._height)
return self.rectxy
except TypeError:
pass