本文整理汇总了Python中matplotlib.patches.Rectangle.get_height方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.get_height方法的具体用法?Python Rectangle.get_height怎么用?Python Rectangle.get_height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.get_height方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [as 别名]
class click_yrange:
'''An interactive yrange selector. Given an axis and a starting
y0 location, draw a full-width rectange that follows the mouise.
Similar to click_window, but more appropriate for selecting out
a y-range.'''
def __init__(self, ax, y0):
self.ax = ax
self.y0 = y0
x0,x1 = ax.get_xbound()
self.rect = Rectangle((x0,y0), width=(x1-x0), height=0, alpha=0.1)
ax.add_artist(self.rect)
def connect(self):
self.cidmotion = self.rect.figure.canvas.mpl_connect(
'motion_notify_event', self.on_motion)
def on_motion(self, event):
# Have we left the axes?
if event.inaxes != self.rect.axes: return
self.rect.set_height(event.ydata - self.y0)
self.ax.figure.canvas.draw()
def close(self):
self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
self.rect.remove()
self.ax.figure.canvas.draw()
return(self.y0, self.rect.get_y()+self.rect.get_height())
示例2: draw_rectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [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
示例3: draw_rectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [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
)
示例4: CustomToolbar
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [as 别名]
#.........这里部分代码省略.........
def release_zoom(self, ev):
if wx.Platform == "__WXMAC__":
self.to_draw.set_visible(False)
NavToolbar.release_zoom(self, ev)
def draw_rubberband(self, event, x0, y0, x1, y1):
# XOR does not work on MacOS ...
if wx.Platform != "__WXMAC__":
NavToolbar.draw_rubberband(self, event, x0, y0, x1, y1)
else:
if self.background is not None:
self.canvas.restore_region(self.background)
c0, c1 = self.ax.transData.inverted().transform([[x0, y0], [x1, y1]])
l, b = c0
r, t = c1
self.to_draw.set_bounds(l, b, r - l, t - b)
self.ax.draw_artist(self.to_draw)
self.canvas.blit(self.ax.bbox)
def update_background(self):
"""force an update of the background"""
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
# Turn on selection
# TODO: Proper handling of states, actual functionality.
def _on_custom_select(self, evt):
# for id in ['Zoom','Pan']:
# self.ToggleTool(self.wx_ids[id], False)
# print('Select ROI: %s' % (self.GetToolState(self.wx_ids['ROI'])))
# self.ToggleTool(self.wx_ids['ROI'],
# self.GetToolState(self.wx_ids['ROI']) )
self.toggle_selector()
# print('Select ROI: %s' % (self.GetToolState(self.wx_ids['ROI'])))
def onSelect(self, eclick, erelease):
"eclick and erelease are matplotlib events at press and release"
# print(' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata))
# print(' endposition : (%f, %f)' % (erelease.xdata, erelease.ydata))
# print(' used button : ', eclick.button)
self.updateROI(
min(eclick.xdata, erelease.xdata),
min(eclick.ydata, erelease.ydata),
abs(eclick.xdata - erelease.xdata),
abs(eclick.ydata - erelease.ydata),
)
if self.canvas.parentFrame.fixedNumberCB.IsChecked():
# We are working in the fixed-number mode
# We need to find new roi for this center point
# The handler will call the update ROI function for us.
self.canvas.parentFrame.handleROIforN()
def updateROI(self, x, y, w, h):
if self.roi is None:
# print('upd ROI:', x, y, w, h)
self.roi = Rectangle((x, y), w, h, ls="solid", lw=2, color="r", fill=False, zorder=5)
self.canvas.figure.axes[0].add_patch(self.roi)
else:
self.roi.set_bounds(x, y, w, h)
self.updateCanvas()
def toggle_selector(self):
self.selector.set_active(not self.selector.active)
def onFixedSize(self, ev):
self.fixedSize = ev.IsChecked()
self.updateCanvas()
def onWidthChange(self, ev):
if self.roi:
x = self.roi.get_x()
w = self.roi.get_width()
nw = ev.GetValue()
dw = {"C": (w - nw) / 2, "L": 0, "R": w - nw}[self.canvas.parentFrame.anchorRB.GetStringSelection()[0]]
self.roi.set_x(x + dw)
self.roi.set_width(nw)
self.updateCanvas()
def onHeightChange(self, ev):
if self.roi:
y = self.roi.get_y()
h = self.roi.get_height()
nh = ev.GetValue()
dh = {"C": (h - nh) / 2, "B": 0, "T": h - nh}[self.canvas.parentFrame.anchorRB.GetStringSelection()[-1]]
self.roi.set_y(y + dh)
self.roi.set_height(nh)
self.updateCanvas()
def updateCanvas(self, redraw=True):
if self.roi:
self.canvas.parentFrame.showROI(
self.roi.get_x(), self.roi.get_y(), self.roi.get_width(), self.roi.get_height()
)
self.canvas.parentFrame.setWH(self.roi.get_width(), self.roi.get_height())
if self.fixedSize:
self.selector.setSize(self.roi.get_width(), self.roi.get_height())
else:
self.selector.setSize()
if redraw:
self.draw()
示例5: handle_event
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [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:
#.........这里部分代码省略.........
示例6: StatsPanel
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [as 别名]
#.........这里部分代码省略.........
def queue_update_stats(self, msg=None):
"""
wrapper to call update_stats from CallAfter in order to make GUI as responsive as possible.
"""
wx.CallAfter(self.update_stats, msg=None)
def _set_stats_box_parameters(self, msg):
"""
wrapper to update_stats_box to receive messages & translate them correctly
"""
x0,x1,y0,y1 = [None]*4
if msg['xrange'] is not None:
x0,x1 = msg['xrange']
if msg['yrange'] is not None:
y0,y1 = msg['yrange']
if msg['xrange'] is not None or msg['yrange'] is not None:
self.update_stats_box(x0, y0, x1, y1)
if msg['show_overplot'] is not None:
if msg['show_overplot']:
self.redraw_overplot_on_image()
else:
self.remove_overplot_on_image()
send_to_stream(sys.stdout, ('set-stats-box-parameters-done', True))
def update_stats_box(self, x0=None, y0=None, x1=None, y1=None):
if x0 is None:
x0 = self.stats_rect.get_x()
if y0 is None:
y0 = self.stats_rect.get_y()
if x1 is None:
x1 = self.stats_rect.get_x() + self.stats_rect.get_width()
if y1 is None:
y1 = self.stats_rect.get_y() + self.stats_rect.get_height()
if x0 > x1:
x0, x1 = x1, x0
if y0 > y1:
y0, y1 = y1, y0
x0 = min(max(0, x0), self.ztv_frame.display_image.shape[1] - 1)
y0 = min(max(0, y0), self.ztv_frame.display_image.shape[0] - 1)
x1 = min(max(0, x1), self.ztv_frame.display_image.shape[1] - 1)
y1 = min(max(0, y1), self.ztv_frame.display_image.shape[0] - 1)
self.stats_rect.set_bounds(x0, y0, x1 - x0, y1 - y0)
if self.hideshow_button.GetLabel() == 'Hide':
self.ztv_frame.primary_image_panel.figure.canvas.draw()
self.update_stats()
def remove_overplot_on_image(self):
self.ztv_frame.primary_image_panel.remove_patch('stats_panel:stats_rect')
self.hideshow_button.SetLabel(u"Show")
def redraw_overplot_on_image(self):
self.ztv_frame.primary_image_panel.add_patch('stats_panel:stats_rect', self.stats_rect)
self.hideshow_button.SetLabel(u"Hide")
def on_hideshow_button(self, evt):
if self.hideshow_button.GetLabel() == 'Hide':
self.remove_overplot_on_image()
else:
self.redraw_overplot_on_image()
def get_x0y0x1y1_from_stats_rect(self):
x0 = self.stats_rect.get_x()
y0 = self.stats_rect.get_y()
x1 = x0 + self.stats_rect.get_width()
y1 = y0 + self.stats_rect.get_height()
示例7: CaseSelector
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [as 别名]
#.........这里部分代码省略.........
w, h = 0, 1
self.rect = Rectangle((0, 0), w, h, transform=trans, visible=False,
animated=True, **self.rectprops)
self.ax.add_patch(self.rect)
self.artists = [self.rect]
# stay rect
self.stay_rects = []
for set in range(0, len(nrect)):
self.stay_rects.append([])
for n in range(0, nrect[set]):
stay_rect = Rectangle((0, 0), w, h, transform=trans, visible=False,
animated=True, **self.stay_rectprops[set])
self.ax.add_patch(stay_rect)
self.stay_rects[set].append(stay_rect)
self.artists.extend(self.stay_rects[set])
# bar
self.bar = ax.axvline(0, w, h, visible=False, **self.lineprops)
self.artists.append(self.bar)
def set_bar_position(self, x):
self.bar.set_xdata(x)
self.bar.set_visible(True)
def set_stay_rects_x_bounds(self, xarr, set=0):
for n, stay_rect in enumerate(self.stay_rects[set]):
try:
xmin, xmax = xarr[n]
except IndexError:
stay_rect.set_visible(False)
else:
stay_rect.set_x(xmin)
stay_rect.set_y(self.rect.get_y())
stay_rect.set_width(abs(xmax - xmin))
stay_rect.set_height(self.rect.get_height())
stay_rect.set_visible(True)
def set_stay_rect_visible(self, b=True, set=0):
for stay_rect in self.stay_rects[set]:
stay_rect.set_visible(b)
def ignore(self, event):
"""return *True* if *event* should be ignored"""
return _SelectorWidget.ignore(self, event) or not self.visible
def _press(self, event):
"""on button press event"""
xdata, ydata = self._get_data(event)
self.pressv = xdata
return False
def _release(self, event):
"""on button release event"""
if self.pressv is None:
return
self.buttonDown = False
self.rect.set_visible(False)
vmin = self.pressv
xdata, ydata = self._get_data(event)
vmax = xdata or self.prev[0]
if vmin > vmax:
vmin, vmax = vmax, vmin
span = vmax - vmin
if span < self.minspan and event.button == 3: # right click to remove span
self.onclick(vmin)
示例8: __init__
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_height [as 别名]
#.........这里部分代码省略.........
from matplotlib.patches import Rectangle
if loaded and self.parent.mask is not None:
import numpy
y,x = numpy.where(self.parent.mask==1)
x0,x1,y0,y1 = x.min(),x.max(),y.min(),y.max()
self.rubberBox = Rectangle((x0,y0),x1-x0,y1-y0,fc='none',ec='w')
self.a1.add_patch(self.rubberBox)
self.canvas.draw()
return
if self.activeButton==self.buttonMask:
self.deactivateButtons()
return
self.deactivateButtons()
self.xmask = None
def onPress(event):
axes = event.inaxes
if axes==self.a1:
self.xmask = event.xdata
self.ymask = event.ydata
if self.rubberBox is not None:
self.rubberBox.remove()
self.rubberBox = None
def onMove(event):
if self.xmask is None:
return
axes = event.inaxes
if axes==self.a1:
x,y = event.xdata,event.ydata
dx = x-self.xmask
dy = y-self.ymask
if self.rubberBox is None:
self.rubberBox = Rectangle((self.xmask,self.ymask),
dx,dy,fc='none',ec='w')
self.a1.add_patch(self.rubberBox)
else:
self.rubberBox.set_height(dy)
self.rubberBox.set_width(dx)
self.canvas.draw()
def onRelease(event):
dy = int(self.rubberBox.get_height())
dx = int(self.rubberBox.get_width())
x0,y0 = int(self.xmask),int(self.ymask)
x1,y1 = x0+dx,y0+dy
self.parent.mask = self.parent.imgs[0]*0
self.parent.mask[y0:y1,x0:x1] = 1
self.parent.mask = self.parent.mask==1
self.deactivateButtons()
self.pressid = self.canvas.mpl_connect('button_press_event',onPress)
self.moveid = self.canvas.mpl_connect('motion_notify_event',onMove)
self.releaseid = self.canvas.mpl_connect('button_release_event',onRelease)
self.bAMtext.set('Cancel')
self.activeButton = self.buttonMask
def showResid(self):
if self.parent.models is None:
self.a2.imshow(self.parent.img,origin='bottom',
interpolation='nearest')
self.a3.cla()
self.a3.set_xticks([])
self.a3.set_yticks([])
self.canvas.show()
return
models = self.parent.models
imgs = self.parent.imgs
nimgs = self.parent.nimgs
if self.color is not None:
if nimgs==2:
b = imgs[0]-models[0]
r = imgs[1]-models[1]
g = (b+r)/2.
resid = self.color.colorize(b,g,r)
b = models[0]
r = models[1]
g = (b+r)/2.
model = self.color.colorize(b,g,r,newI=True)
else:
b = imgs[0]-models[0]
g = imgs[1]-models[1]
r = imgs[2]-models[2]
resid = self.color.colorize(b,g,r)
b = models[0]
g = models[1]
r = models[2]
model = self.color.colorize(b,g,r,newI=True)
else:
resid = imgs[0]-models[0]
model = models[0]
self.img3.set_clim([0.,model.max()])
#self.a2.imshow(resid,origin='bottom',interpolation='nearest')
#self.a3.imshow(model,origin='bottom',interpolation='nearest')
self.img2.set_data(resid)
self.img3.set_data(model)
self.canvas.draw()
def redrawSymbols(self):
import objectMover
if self.mover is not None:
self.mover.remove()
self.mover = objectMover.ObjMover(self.parent,self.a4,self.canvas)