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


Python Polygon.set_visible方法代码示例

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


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

示例1: ScatterPlotWidget

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_visible [as 别名]
class ScatterPlotWidget(wx.Panel, ManageBusyCursorMixin):

    def __init__(self, parent, scatt_id, scatt_mgr, transpose,
                 id=wx.ID_ANY):
        # TODO should not be transpose and scatt_id but x, y
        wx.Panel.__init__(self, parent, id)
        # bacause of aui (if floatable it can not take cursor from parent)
        ManageBusyCursorMixin.__init__(self, window=self)

        self.parent = parent
        self.full_extend = None
        self.mode = None

        self._createWidgets()
        self._doLayout()
        self.scatt_id = scatt_id
        self.scatt_mgr = scatt_mgr

        self.cidpress = None
        self.cidrelease = None

        self.rend_dt = {}

        self.transpose = transpose

        self.inverse = False

        self.SetSize((200, 100))
        self.Layout()

        self.base_scale = 1.2
        self.Bind(wx.EVT_CLOSE, lambda event: self.CleanUp())

        self.plotClosed = Signal("ScatterPlotWidget.plotClosed")
        self.cursorMove = Signal("ScatterPlotWidget.cursorMove")

        self.contex_menu = ScatterPlotContextMenu(plot=self)

        self.ciddscroll = None

        self.canvas.mpl_connect('motion_notify_event', self.Motion)
        self.canvas.mpl_connect('button_press_event', self.OnPress)
        self.canvas.mpl_connect('button_release_event', self.OnRelease)
        self.canvas.mpl_connect('draw_event', self.DrawCallback)
        self.canvas.mpl_connect('figure_leave_event', self.OnCanvasLeave)

    def DrawCallback(self, event):
        self.polygon_drawer.DrawCallback(event)
        self.axes.draw_artist(self.zoom_rect)

    def _createWidgets(self):

        # Create the mpl Figure and FigCanvas objects.
        # 5x4 inches, 100 dots-per-inch
        #
        self.dpi = 100
        self.fig = Figure((1.0, 1.0), dpi=self.dpi)
        self.fig.autolayout = True

        self.canvas = FigCanvas(self, -1, self.fig)

        self.axes = self.fig.add_axes([0.0, 0.0, 1, 1])

        pol = Polygon(list(zip([0], [0])), animated=True)
        self.axes.add_patch(pol)
        self.polygon_drawer = PolygonDrawer(self.axes, pol=pol, empty_pol=True)

        self.zoom_wheel_coords = None
        self.zoom_rect_coords = None
        self.zoom_rect = Polygon(list(zip([0], [0])), facecolor='none')
        self.zoom_rect.set_visible(False)
        self.axes.add_patch(self.zoom_rect)

    def ZoomToExtend(self):
        if self.full_extend:
            self.axes.axis(self.full_extend)
            self.canvas.draw()

    def SetMode(self, mode):
        self._deactivateMode()
        if mode == 'zoom':
            self.ciddscroll = self.canvas.mpl_connect(
                'scroll_event', self.ZoomWheel)
            self.mode = 'zoom'
        elif mode == 'zoom_extend':
            self.mode = 'zoom_extend'
        elif mode == 'pan':
            self.mode = 'pan'
        elif mode:
            self.polygon_drawer.SetMode(mode)

    def SetSelectionPolygonMode(self, activate):
        self.polygon_drawer.SetSelectionPolygonMode(activate)

    def _deactivateMode(self):
        self.mode = None
        self.polygon_drawer.SetMode(None)

        if self.ciddscroll:
            self.canvas.mpl_disconnect(self.ciddscroll)
#.........这里部分代码省略.........
开发者ID:rkrug,项目名称:grass-ci,代码行数:103,代码来源:plots.py

示例2: MplPolygonalROI

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_visible [as 别名]
class MplPolygonalROI(AbstractMplRoi):
    """
    Matplotlib ROI for polygon selections

    Parameters
    ----------
    axes : `~matplotlib.axes.Axes`
        The Matplotlib axes to draw to.
    roi : `~glue.core.roi.Roi`, optional
        If specified, this ROI will be used and updated, otherwise a new one
        will be created.
    """

    _roi_cls = PolygonalROI

    def __init__(self, axes, roi=None):

        super(MplPolygonalROI, self).__init__(axes, roi=roi)

        self.plot_opts = {'edgecolor': PATCH_COLOR,
                          'facecolor': PATCH_COLOR,
                          'alpha': 0.3}

        self._patch = Polygon(np.array(list(zip([0, 1], [0, 1]))), zorder=100)
        self._patch.set_visible(False)
        self._axes.add_patch(self._patch)

    def _sync_patch(self):
        if self._roi.defined():
            x, y = self._roi.to_polygon()
            self._patch.set_xy(list(zip(x + [x[0]],
                                        y + [y[0]])))
            self._patch.set_visible(True)
            self._patch.set(**self.plot_opts)
        else:
            self._patch.set_visible(False)

    def start_selection(self, event, scrubbing=False):

        if event.inaxes != self._axes:
            return False

        if scrubbing or event.key == SCRUBBING_KEY:
            if not self._roi.defined():
                return False
            elif not self._roi.contains(event.xdata, event.ydata):
                return False

        self._store_previous_roi()
        self._store_background()

        if scrubbing or event.key == SCRUBBING_KEY:
            self._scrubbing = True
            self._cx = event.xdata
            self._cy = event.ydata
        else:
            self.reset()
            self._roi.add_point(event.xdata, event.ydata)

        self._mid_selection = True

        self._sync_patch()
        self._draw()

    def update_selection(self, event):

        if not self._mid_selection or event.inaxes != self._axes:
            return False

        if event.key == SCRUBBING_KEY:
            if not self._roi.defined():
                return False

        if self._scrubbing:
            self._roi.move_to(event.xdata - self._cx,
                              event.ydata - self._cy)
            self._cx = event.xdata
            self._cy = event.ydata
        else:
            self._roi.add_point(event.xdata, event.ydata)

        self._sync_patch()
        self._draw()

    def finalize_selection(self, event):
        self._scrubbing = False
        self._mid_selection = False
        self._patch.set_visible(False)
        self._draw()
开发者ID:glue-viz,项目名称:glue,代码行数:91,代码来源:roi.py

示例3: MplPolygonalROI

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_visible [as 别名]
class MplPolygonalROI(AbstractMplRoi):

    """
    Defines and displays polygonal ROIs on matplotlib plots

    Attributes:

        plot_opts: Dictionary instance
                   A dictionary of plot keywords that are passed to
                   the patch representing the ROI. These control
                   the visual properties of the ROI
    """

    def __init__(self, axes):
        """
        :param axes: A matplotlib Axes object to attach the graphical ROI to
        """
        AbstractMplRoi.__init__(self, axes)
        self.plot_opts = {'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR,
                          'alpha': 0.3}

        self._setup_patch()

    def _setup_patch(self):
        self._patch = Polygon(np.array(list(zip([0, 1], [0, 1]))))
        self._patch.set_zorder(100)
        self._patch.set(**self.plot_opts)
        self._axes.add_patch(self._patch)
        self._patch.set_visible(False)
        self._sync_patch()

    def _roi_factory(self):
        return PolygonalROI()

    def _sync_patch(self):
        # Update geometry
        if not self._roi.defined():
            self._patch.set_visible(False)
        else:
            x, y = self._roi.to_polygon()
            self._patch.set_xy(list(zip(x + [x[0]],
                                        y + [y[0]])))
            self._patch.set_visible(True)

        # Update appearance
        self._patch.set(**self.plot_opts)

        # Refresh
        self._axes.figure.canvas.draw()

    def start_selection(self, event):

        if event.inaxes != self._axes:
            return False

        if event.key == SCRUBBING_KEY:
            if not self._roi.defined():
                return False
            elif not self._roi.contains(event.xdata, event.ydata):
                return False

        self._roi_store()

        if event.key == SCRUBBING_KEY:
            self._scrubbing = True
            self._cx = event.xdata
            self._cy = event.ydata
        else:
            self.reset()
            self._roi.add_point(event.xdata, event.ydata)

        self._mid_selection = True
        self._sync_patch()

    def update_selection(self, event):

        if not self._mid_selection or event.inaxes != self._axes:
            return False

        if event.key == SCRUBBING_KEY:
            if not self._roi.defined():
                return False

        if self._scrubbing:
            self._roi.move_to(event.xdata - self._cx,
                              event.ydata - self._cy)
            self._cx = event.xdata
            self._cy = event.ydata
        else:
            self._roi.add_point(event.xdata, event.ydata)

        self._sync_patch()

    def finalize_selection(self, event):
        self._scrubbing = False
        self._mid_selection = False
        self._patch.set_visible(False)
        self._axes.figure.canvas.draw()
开发者ID:saimn,项目名称:glue,代码行数:100,代码来源:roi.py

示例4: ScatterGraph

# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_visible [as 别名]
  def ScatterGraph(self):
    AnnotatedArtists = []

    #
    # Compute the scatter plot for this cluster
    #
    NumberOfFrames  = self.Data.GetNumberOfFrames()
    NumberOfObjects = self.Data.GetNumberOfObjects()
    FirstObject     = self.Data.GetFirstObject() - 2 # Include filtered and noise
    LastObject      = self.Data.GetLastObject()
    TasksPerFrame   = self.Data.GetTasksPerFrame()

    SelectedFrame   = self.GUI.GetSelectedFrame()
    SelectedCluster  = self.GUI.GetSelectedCluster()
    SelectedMetricX = self.GUI.GetSelectedMetricX()
    SelectedMetricY = self.GUI.GetSelectedMetricY()
    if self.GUI.in_3D():
      SelectedMetricZ = self.GUI.GetSelectedMetricZ()

#    cursor = Cursor(self.ScatterPlotAxes, useblit=True, color='black', linewidth=1 )

    for current_frame in range(1, NumberOfFrames+1):

      for current_object in range(FirstObject, LastObject+1):
        (r, g, b) = Decorations.RGBColor0_1(current_object)

        # 
        # Compute the scatter plot for this cluster
        # 
        xdata = self.Data.GetClusterData( current_frame, current_object, SelectedMetricX )
        ydata = self.Data.GetClusterData( current_frame, current_object, SelectedMetricY )
        if (len(xdata) == 0) or (len(ydata) == 0):
          continue
        if self.GUI.in_3D():
          zdata = self.Data.GetClusterData( current_frame, current_object, SelectedMetricZ )
          if (len(zdata) == 0):
            continue

        if (self.GUI.in_Trajectory_View()):
          if self.GUI.RatioX():
            xdata = xdata * TasksPerFrame[current_frame-1]
          if self.GUI.RatioY():
            ydata = ydata * TasksPerFrame[current_frame-1]
          if self.GUI.in_3D() and self.GUI.RatioZ():
            zdata = zdata * TasksPerFrame[current_frame-1]

        if self.GUI.in_3D():
          scatter = self.ScatterPlotAxes.scatter( xdata, ydata, zdata, color=(r, g, b), zorder=2, s=50, marker=Decorations.ChooseMarker(current_object), picker=True )
        else:
          scatter = self.ScatterPlotAxes.scatter( xdata, ydata, color=(r, g, b), zorder=2, s=50, marker=Decorations.ChooseMarker(current_object), picker=True )
        thumb = self.GUI.GetThumbAxes(current_frame).scatter( xdata, ydata, color=(r, g, b), zorder=2, s=100, marker=Decorations.ChooseMarker(current_object))
        thumb.set_visible( False )
        self.Thumbs[(current_object, current_frame)] = thumb

        scatter.set_gid( self.Data.PrettyCluster(current_object) )
        scatter.set_visible( False )
        self.Scatters[(current_object, current_frame)] = scatter
        AnnotatedArtists.append( scatter )

        # 
        # Compute the centroid for this cluster
        # 
        centroid_x = nanmean( xdata )
        centroid_y = nanmean( ydata )
        if self.GUI.in_3D():
          centroid_z = nanmean( zdata )
          centroid = self.ScatterPlotAxes.scatter( centroid_x, centroid_y, centroid_z, s=50, color=(r, g, b), edgecolor="black", marker="o", zorder=3, picker=True )
          self.Trajectories[(current_object, current_frame)] = (centroid_x, centroid_y, centroid_z)
        else:
          centroid = self.ScatterPlotAxes.scatter( centroid_x, centroid_y, s=50, color=(r, g, b), edgecolor="black", marker="o", zorder=3, picker=True)
          self.Trajectories[(current_object, current_frame)] = (centroid_x, centroid_y)

        centroid.set_gid( self.Data.PrettyCluster(current_object) )
        centroid.set_visible(False)
        self.Centroids[(current_object, current_frame)] = centroid
        AnnotatedArtists.append( centroid )

        # 
        # Compute the convex hull for this cluster
        # 
        if (AvailableHulls) and self.GUI.in_2D():
          points = np.array( zip(xdata, ydata) )
          if (len(points) < 3):
            continue

          try:
            hull     = ConvexHull( points, qhull_options='Pp' )
            vertices = hull.vertices
          except:
            vertices = []
 
          if (len(vertices) > 0):
            polygon_points = []
            for vertice in vertices:
              polygon_points.append( (points[vertice][0], points[vertice][1]) )
           
            hull_polygon = Polygon(polygon_points, closed=True, alpha=0.5, color=Decorations.RGBColor0_1(current_object), zorder=4, lw=10)
            hull_polygon.set_gid( self.Data.PrettyCluster(current_object) )
            hull_polygon.set_visible(False)
            self.Hulls[(current_object, current_frame)] = hull_polygon
#.........这里部分代码省略.........
开发者ID:gllort,项目名称:xtrack,代码行数:103,代码来源:plotting_manager.py


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