Beispiel #1
0
class ClipWindow:
    def __init__(self, ax, line):
        self.ax = ax
        ax.set_title('drag polygon around to test clipping')
        self.canvas = ax.figure.canvas
        self.line = line
        self.poly = RegularPolygon((200, 200),
                                   numVertices=10,
                                   radius=100,
                                   facecolor='yellow',
                                   alpha=0.25,
                                   transform=transforms.IdentityTransform())

        ax.add_patch(self.poly)
        self.canvas.mpl_connect('button_press_event', self.onpress)
        self.canvas.mpl_connect('button_release_event', self.onrelease)
        self.canvas.mpl_connect('motion_notify_event', self.onmove)
        self.x, self.y = None, None

    def onpress(self, event):
        self.x, self.y = event.x, event.y

    def onrelease(self, event):
        self.x, self.y = None, None

    def onmove(self, event):

        if self.x is None: return
        dx = event.x - self.x
        dy = event.y - self.y
        self.x, self.y = event.x, event.y
        x, y = self.poly.xy
        x += dx
        y += dy
        #print self.y, event.y, dy, y
        self.poly.xy = x, y
        self._clip()

    def _clip(self):
        self.line.set_clip_path(self.poly.get_path(),
                                self.poly.get_transform())
        self.canvas.draw_idle()
Beispiel #2
0
class ClipWindow:
    def __init__(self, ax, line):
        self.ax = ax
        ax.set_title('drag polygon around to test clipping')
        self.canvas = ax.figure.canvas
        self.line = line
        self.poly = RegularPolygon(
            (200, 200), numVertices=10, radius=100,
            facecolor='yellow', alpha=0.25,
            transform=transforms.IdentityTransform())

        ax.add_patch(self.poly)
        self.canvas.mpl_connect('button_press_event', self.onpress)
        self.canvas.mpl_connect('button_release_event', self.onrelease)
        self.canvas.mpl_connect('motion_notify_event', self.onmove)
        self.x, self.y = None, None

    def onpress(self, event):
        self.x, self.y = event.x, event.y

    def onrelease(self, event):
        self.x, self.y = None, None

    def onmove(self, event):

        if self.x is None: return
        dx = event.x - self.x
        dy = event.y - self.y
        self.x, self.y = event.x, event.y
        x, y = self.poly.xy
        x += dx
        y += dy
        #print self.y, event.y, dy, y
        self.poly.xy = x,y
        self._clip()

    def _clip(self):
        self.line.set_clip_path(self.poly.get_path(), self.poly.get_transform())
        self.canvas.draw_idle()
Beispiel #3
0
    def get_nodes_within_hexagon(self, center, radius, stream_id):
        """
        Get nodes inside a hexagon

        :param center: x+yj
        :param radius: float
        :param stream_id: str
        :return: array of ints (neuron indices)
        """

        output_grid = self.corem_positions[stream_id]

        hexagon = RegularPolygon((center.real, center.imag), 6, radius=radius)
        hexagon_path = hexagon.get_path(
        )  # matplotlib returns the unit hexagon
        hexagon_tf = hexagon.get_transform(
        )  # which can then be transformed to give the real path
        real_hexagon_path = hexagon_tf.transform_path(hexagon_path)

        output_grid_tuples = [(z.real, z.imag) for z in output_grid]
        wanted_indices = np.where(
            real_hexagon_path.contains_points(output_grid_tuples))

        return wanted_indices[0]