本文整理汇总了Python中matplotlib.patches.Rectangle.get_y方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.get_y方法的具体用法?Python Rectangle.get_y怎么用?Python Rectangle.get_y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.get_y方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_y [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: CustomToolbar
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_y [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()
示例3: StatsPanel
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_y [as 别名]
#.........这里部分代码省略.........
def set_cursor_to_stats_box_mode(self, event):
self.ztv_frame.primary_image_panel.cursor_mode = 'Stats box'
self.ztv_frame.stats_panel.select_panel()
self.ztv_frame.stats_panel.highlight_panel()
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):
示例4: CaseSelector
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_y [as 别名]
#.........这里部分代码省略.........
# span
trans = blended_transform_factory(self.ax.transData, self.ax.transAxes)
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
示例5: rectSelector
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_y [as 别名]
class rectSelector(object):
def __init__(self, fig, df):
self.fig = fig
self.df = df
self.cid_on = fig.canvas.mpl_connect('button_press_event', self)
self.cid_off = fig.canvas.mpl_connect('button_release_event', self)
self.cid_move = None
self.feats = {'lim1': [-np.inf, +np.inf], 'lim2': [-np.inf, +np.inf], 'feat1': None, 'feat2': None}
self.rect = None
def __call__(self, event):
if event.inaxes is None: return
if event.name=='button_press_event':
self.on_press(event)
elif event.name=='button_release_event':
self.on_release(event)
def on_press(self, event):
if self.rect is not None:
self.rect.remove()
self.feats['lim1'] = [-np.inf, +np.inf]
self.feats['lim2'] = [-np.inf, +np.inf]
(feat1, feat2) = [feat for ax, feat in ax2feat.iteritems() if ax==event.inaxes][0]
self.feats = {'feat1': feat1, 'feat2': feat2,
'lim1': [event.xdata]*2, 'lim2':[event.ydata]*2}
self.rect = Rectangle([event.xdata, event.ydata], 0., 0., alpha=0.3)
event.inaxes.add_patch(self.rect)
self.cid_move = self.fig.canvas.mpl_connect('motion_notify_event', self.on_move)
def on_release(self, event):
self.fig.canvas.mpl_disconnect(self.cid_move)
def on_move(self, event):
if event.inaxes is None:
return
# resize the rectangle so the new width tracks the mouse pointer
self.rect.set_width(event.xdata - self.rect.get_x())
self.rect.set_height(event.ydata - self.rect.get_y())
# update the limits for each feature
self.feats['lim1'] = [self.rect.get_x(), event.xdata]
if event.xdata<self.rect.get_x():
self.feats['lim1'] = self.feats['lim1'][::-1]
self.feats['lim2'] = [self.rect.get_y(), event.ydata]
if event.ydata<self.rect.get_y():
self.feats['lim2'] = self.feats['lim2'][::-1]
self.filterData()
def filterData(self):
feat1 = self.feats['feat1']
feat2 = self.feats['feat2']
lim1 = self.feats['lim1']
lim2 = self.feats['lim2']
df = self.df
ix = np.vstack((df[feat1]>lim1[0], df[feat1]<lim1[1],
df[feat2]>lim2[0], df[feat2]<lim2[1])).all(0)
colors = np.array([colordict[i] for i in df['species']], dtype = 'S4')
colors[~ix] = 'gray'
for sc in scatters:
sc.set_color(colors)
plt.show()
示例6: ComboBox
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_y [as 别名]
#.........这里部分代码省略.........
if _DEV:
print("unhandled %s --> %s" % (self._cb_state, new_state))
def _on_mouse_down(self, event):
if event.inaxes not in [self._axes, self._select_axes]:
self._ignore_edit_notify = True
if self._cb_state != ComboState.IDLE:
self._cb_change_state(ComboState.IDLE)
super(ComboBox, self)._on_mouse_down(event)
return
x, y = event.xdata, event.ydata
if x is None or y is None:
super(ComboBox, self)._on_mouse_down(event)
return
if self._cb_state == ComboState.IDLE:
cx = self._select_posx
d = np.sqrt( (x - cx) ** 2 )
if d <= 0.16:
self._cb_change_state(ComboState.DROP_SELECT)
else:
super(ComboBox, self)._on_mouse_down(event)
elif self._cb_state == ComboState.DROP_SELECT:
y = self._select_highlight.get_y()
idx = self._find_text_entry(y)
selection = self._text_list[idx]
self._ignore_edit_notify = True
self.text(selection)
if self._selection_notify:
self._selection_notify(idx, selection)
self._cb_change_state(ComboState.IDLE)
elif _DEV:
print("on_mouse_down(): unhandled %s" % self._cb_state)
def _on_mouse_motion(self, event):
if event.inaxes != self._select_axes:
return
x, y = event.xdata, event.ydata
if x is None or y is None:
return
if self._cb_state == ComboState.DROP_SELECT:
idx = self._find_text_entry(y)