当前位置: 首页>>代码示例>>Python>>正文


Python Rectangle.get_x方法代码示例

本文整理汇总了Python中matplotlib.patches.Rectangle.get_x方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.get_x方法的具体用法?Python Rectangle.get_x怎么用?Python Rectangle.get_x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.patches.Rectangle的用法示例。


在下文中一共展示了Rectangle.get_x方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_x [as 别名]
class click_xrange:
   '''An interactive xrange selector.  Given an axis and a starting
   x0 location, draw a full-height rectange that follows the mouise.
   Similar to click_window, but more appropriate for selecting out
   an x-range.'''

   def __init__(self, ax, x0):
      self.ax = ax
      self.x0 = x0
      y0,y1 = ax.get_ybound()
      self.rect = Rectangle((x0,y0), width=0, height=(y1-y0), 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_width(event.xdata - self.x0)
      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.x0, self.rect.get_x()+self.rect.get_width())
开发者ID:obscode,项目名称:snpy,代码行数:31,代码来源:plot_sne_mpl.py

示例2: CustomToolbar

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_x [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()
开发者ID:jochym,项目名称:pointsel,代码行数:104,代码来源:pointsel.py

示例3: StatsPanel

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_x [as 别名]

#.........这里部分代码省略.........
        self.update_stats()

    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()
开发者ID:henryroe,项目名称:ztv,代码行数:70,代码来源:stats_panel.py

示例4: WindowSelectionRectangle

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_x [as 别名]
class WindowSelectionRectangle(object):
    def __init__(self, event, axis, on_window_selection_callback):
        self.axis = axis
        if event.inaxes != self.axis:
            return
        # Store the axes it has been initialized in.
        self.axes = event.inaxes
        ymin, ymax = self.axes.get_ylim()
        self.min_x = event.xdata
        self.intial_selection_active = True
        self.rect = Rectangle((event.xdata, ymin), 0, ymax - ymin, color="0.3",
            alpha=0.5, edgecolor="0.5")
        self.axes.add_patch(self.rect)
        # Get the canvas.
        self.canvas = self.rect.figure.canvas

        # Use blittig for fast animations.
        self.rect.set_animated(True)
        self.background = self.canvas.copy_from_bbox(self.rect.axes.bbox)

        self._connect()

        self.on_window_selection_callback = on_window_selection_callback

    #def __del__(self):
        #"""
        #Disconnect the events upon deallocating.
        #"""
        #self.canvas.mpl_disconnect(self.conn_button_press)
        #self.canvas.mpl_disconnect(self.conn_button_release)
        #self.canvas.mpl_disconnect(self.conn_mouse_motion)

    def _connect(self):
        """
        Connect to the necessary events.
        """
        self.conn_button_press = self.rect.figure.canvas.mpl_connect(
            'button_press_event', self.on_button_press)
        self.conn_button_release = self.rect.figure.canvas.mpl_connect(
            'button_release_event', self.on_button_release)
        self.conn_mouse_motion = self.rect.figure.canvas.mpl_connect(
            'motion_notify_event', self.on_mouse_motion)

    def on_button_press(self, event):
        pass

    def on_button_release(self, event):
        if event.inaxes != self.axis:
            return

        if event.button != 1:
            return
        # turn off the rect animation property and reset the background
        self.rect.set_animated(False)
        self.background = None

        self.intial_selection_active = False
        self.canvas.draw()

        x = self.rect.get_x()
        width = self.rect.get_width()

        if width < 0:
            x = x + width
            width = abs(width)

        self.on_window_selection_callback(x, width, self.axis)

    def on_mouse_motion(self, event):
        if event.button != 1 or \
                self.intial_selection_active is not True:
            return
        if event.xdata is not None:
            self.rect.set_width(event.xdata - self.min_x)

        # restore the background region
        self.canvas.restore_region(self.background)
        # redraw just the current rectangle
        self.axes.draw_artist(self.rect)
        # blit just the redrawn area
        self.canvas.blit(self.axes.bbox)
开发者ID:msimon00,项目名称:LASIF,代码行数:83,代码来源:matplotlib_selection_rectangle.py

示例5: rectSelector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import get_x [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()
开发者ID:r-b-g-b,项目名称:AY250_HW,代码行数:80,代码来源:hw3_3.py


注:本文中的matplotlib.patches.Rectangle.get_x方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。