コード例 #1
0
ファイル: diaggeom_aug.py プロジェクト: shmuller/pytokamak
    def _transform_from_image(self):
        from matplotlib.transforms import Bbox, BboxTransform

        ref_im = np.array([(15.152, 57.079), (15.152, 65.091),
                           (12.949, 65.091), (12.949, 62.575), (5.613, 62.575),
                           (5.613, 60.587), (12.949, 60.587),
                           (12.949, 57.079)])

        ref = Vessel().digitizer.xy[2]

        bbox_im, bbox = Bbox.unit(), Bbox.unit()
        bbox_im.update_from_data_xy(ref_im)
        bbox.update_from_data_xy(ref)
        trans = BboxTransform(bbox_im, bbox)
        return trans
コード例 #2
0
ファイル: inset_locator.py プロジェクト: Iain-S/matplotlib
 def connect_bbox(bbox1, bbox2, loc1, loc2=None):
     """
     Construct a `.Path` connecting corner *loc1* of *bbox1* to corner
     *loc2* of *bbox2*, where parameters behave as documented as for the
     `.BboxConnector` constructor.
     """
     if isinstance(bbox1, Rectangle):
         bbox1 = TransformedBbox(Bbox.unit(), bbox1.get_transform())
     if isinstance(bbox2, Rectangle):
         bbox2 = TransformedBbox(Bbox.unit(), bbox2.get_transform())
     if loc2 is None:
         loc2 = loc1
     x1, y1 = BboxConnector.get_bbox_edge_pos(bbox1, loc1)
     x2, y2 = BboxConnector.get_bbox_edge_pos(bbox2, loc2)
     return Path([[x1, y1], [x2, y2]])
コード例 #3
0
 def _set_lim_and_transforms(self):
     self.transAxes = BboxTransformTo(self.bbox)
     self.transScale = TransformWrapper(IdentityTransform())
     self.transProjection = self.PolarTransform()
     self.transProjectionAffine = self.PolarAffine(self.transScale, self.viewLim)
     self.transData = self.transScale + self.transProjection + \
         (self.transProjectionAffine + self.transAxes)
     self._xaxis_transform = (
         self.transProjection +
         self.PolarAffine(IdentityTransform(), Bbox.unit()) +
         self.transAxes)
     self._theta_label1_position = Affine2D().translate(0.0, 1.1)
     self._xaxis_text1_transform = (
         self._theta_label1_position +
         self._xaxis_transform)
     self._theta_label2_position = Affine2D().translate(0.0, 1.0 / 1.1)
     self._xaxis_text2_transform = (
         self._theta_label2_position +
         self._xaxis_transform)
     self._yaxis_transform = (
         Affine2D().scale(npy.pi * 2.0, 1.0) +
         self.transData)
     self._r_label1_position = Affine2D().translate(22.5, self._rpad)
     self._yaxis_text1_transform = (
         self._r_label1_position +
         Affine2D().scale(1.0 / 360.0, 1.0) +
         self._yaxis_transform
         )
     self._r_label2_position = Affine2D().translate(22.5, self._rpad)
     self._yaxis_text2_transform = (
         self._r_label2_position +
         Affine2D().scale(1.0 / 360.0, 1.0) +
         self._yaxis_transform
         )
コード例 #4
0
        def _set_lim_and_transforms(self):
            PolarAxes._set_lim_and_transforms(self)
            try:
                theta_position = self._theta_label1_position
            except AttributeError:
                theta_position = self.get_theta_offset()

            self.transProjection = self.GlobeCrossSectionTransform()
            self.transData = (
                self.transScale +
                self.transProjection +
                (self.transProjectionAffine + self.transAxes))
            self._xaxis_transform = (
                self.transProjection +
                self.PolarAffine(IdentityTransform(), Bbox.unit()) +
                self.transAxes)
            self._xaxis_text1_transform = (
                theta_position +
                self._xaxis_transform)
            self._yaxis_transform = (
                Affine2D().scale(num.pi * 2.0, 1.0) +
                self.transData)

            try:
                rlp = getattr(self, '_r_label1_position')
            except AttributeError:
                rlp = getattr(self, '_r_label_position')

            self._yaxis_text1_transform = (
                rlp +
                Affine2D().scale(1.0 / 360.0, 1.0) +
                self._yaxis_transform)
コード例 #5
0
ファイル: polar_axes.py プロジェクト: gbtami/innstereo
    def _set_lim_and_transforms(self):
        """
        Overrides the method with the same name in the PolarAxes-class.

        This method replaces the same method in the PolarAxes-class. It ensures
        that the limits and label placement fit the north-polar projection.
        """
        PolarAxes._set_lim_and_transforms(self)
        self.transProjection = self.NorthPolarTransform()
        # pylint: attribute-defined-outside-init,invalid-name
        self.transData = (
            self.transScale + 
            self.transProjection + 
            (self.transProjectionAffine + self.transAxes))
        # pylint: attribute-defined-outside-init,invalid-name
        self._xaxis_transform = (
            self.transProjection +
            self.PolarAffine(IdentityTransform(), Bbox.unit()) +
            self.transAxes)  # pylint: attribute-defined-outside-init
        self._xaxis_text1_transform = (
            self._theta_label1_position +
            self._xaxis_transform)  # pylint: attribute-defined-outside-init
        self._yaxis_transform = (
            Affine2D().scale(np.pi * 2.0, 1.0) +
            self.transData)  # pylint: attribute-defined-outside-init
        self._yaxis_text1_transform = (
            Affine2D().scale(1.0 / 360.0, 1.0) +
            self._yaxis_transform)  # pylint: attribute-defined-outside-init
コード例 #6
0
    def _set_lim_and_transforms(self):
        """
        Overrides the method with the same name in the PolarAxes-class.

        This method replaces the same method in the PolarAxes-class. It ensures
        that the limits and label placement fit the north-polar projection.
        """
        PolarAxes._set_lim_and_transforms(self)
        self.transProjection = self.NorthPolarTransform()
        # pylint: attribute-defined-outside-init,invalid-name
        self.transData = (self.transScale + self.transProjection +
                          (self.transProjectionAffine + self.transAxes))
        # pylint: attribute-defined-outside-init,invalid-name
        self._xaxis_transform = (
            self.transProjection +
            self.PolarAffine(IdentityTransform(), Bbox.unit()) + self.transAxes
        )  # pylint: attribute-defined-outside-init
        self._xaxis_text1_transform = (
            self._theta_label1_position + self._xaxis_transform
        )  # pylint: attribute-defined-outside-init
        self._yaxis_transform = (Affine2D().scale(np.pi * 2.0, 1.0) +
                                 self.transData
                                 )  # pylint: attribute-defined-outside-init
        self._yaxis_text1_transform = (
            Affine2D().scale(1.0 / 360.0, 1.0) + self._yaxis_transform
        )  # pylint: attribute-defined-outside-init
コード例 #7
0
	def _set_lim_and_transforms(self):
		PolarAxes._set_lim_and_transforms(self)
		self.transProjection = self.NorthPolarTransform()
		self.axisProjection = self.NorthPolarAxisTransform()
		self.transData = (
			Affine2D().scale(numpy.pi/180.0, 1.0/90.0) + 
			self.transScale + 
			self.transProjection + 
			(self.transProjectionAffine + self.transAxes))
		self._xaxis_pretransform = (
			Affine2D().scale(1.0, 1.0) )
		self._xaxis_transform = (
			self._xaxis_pretransform + 
			self.axisProjection +
			self.PolarAffine(IdentityTransform(), Bbox.unit()) +
			self.transAxes)
		self._xaxis_text1_transform = (
			self._theta_label1_position +
			self._xaxis_transform)
		self._yaxis_transform = (
			Affine2D().scale(numpy.pi*2.0, 1.0) + 
			self.transScale + 
			self.axisProjection + 
			(self.transProjectionAffine + self.transAxes))
		self._yaxis_text1_transform = (
			self._r_label1_position +
			Affine2D().translate(0.0, -0.051) +
			self._yaxis_transform)
コード例 #8
0
    def draw_plot(self):
        if self._doRePlot:
            self._resizeCreateContent()
        if self.background is None:
            self.background = self.canvas.copy_from_bbox(self.ax.bbox)
        self.foo += 1
        #self.y = numpy.cos(numpy.arange(0.0,1.0,0.1)+self.foo*0.1)
        # Optimization on the blitting: we compute the box where the changes happen
        changes_box = None

        for i in range(len(self.lines)):
            data = self.channels[i].getNext()

            if len(data[1]) > 0:
                if self.autolim:
                    print self.autolim[0], data[1], self.autolim[1]
                    self.autolim = [ min(self.autolim[0], min(data[1])), \
                        max(self.autolim[1], max(data[1])) ]
                else:
                    self.autolim = [min(data[1]), min(data[1])]

                if changes_box is None:
                    changes_box = Bbox.unit()
                print '>>>>>>>>'
                print data[0], data[1]
                changes_box.update_from_data(numpy.array(data[0]), \
                        numpy.array(data[1]), ignore=changes_box.is_unit())

                if not self._doRePlot and len(data[0]) > 0:
                    end = data[0][-1]

                    if end > self.begin + self.span:
                        self.begin += self.span
                        self._doRePlot = True
                        print 'do replot'
                self.lines[i].set_data(data[0], data[1])
            else:
                self.lines[i].set_data([], [])

        if not changes_box:
            return
        #self.canvas.restore_region(self.background)
        for line in self.lines:
            self.ax.draw_artist(line)
            #print line.get_transform()
            tr = line.get_transform()

        changes_box_inframe = changes_box.transformed(tr)

        box_padding = 5
        (x, y, l, w) = changes_box_inframe.bounds
        changes_box_inframe = Bbox.from_bounds(x-box_padding, \
            y-box_padding, l+2*box_padding, w+2*box_padding)

        #print
        t0 = time.time()
        self.canvas.blit(None)
        #self.canvas.blit(changes_box_inframe)
        self.blit_time += time.time() - t0
コード例 #9
0
    def _set_lim_and_transforms(self):
        self.transAxes = BboxTransformTo(self.bbox)

        # Transforms the x and y axis separately by a scale factor
        # It is assumed that this part will have non-linear components
        self.transScale = TransformWrapper(IdentityTransform())

        # A (possibly non-linear) projection on the (already scaled)
        # data.  This one is aware of rmin
        self.transProjection = self.PolarTransform(self)

        # This one is not aware of rmin
        self.transPureProjection = self.PolarTransform()

        # An affine transformation on the data, generally to limit the
        # range of the axes
        self.transProjectionAffine = self.PolarAffine(self.transScale, self.viewLim)

        # The complete data transformation stack -- from data all the
        # way to display coordinates
        self.transData = self.transScale + self.transProjection + \
            (self.transProjectionAffine + self.transAxes)

        # This is the transform for theta-axis ticks.  It is
        # equivalent to transData, except it always puts r == 1.0 at
        # the edge of the axis circle.
        self._xaxis_transform = (
            self.transPureProjection +
            self.PolarAffine(IdentityTransform(), Bbox.unit()) +
            self.transAxes)
        # The theta labels are moved from radius == 0.0 to radius == 1.1
        self._theta_label1_position = Affine2D().translate(0.0, 1.1)
        self._xaxis_text1_transform = (
            self._theta_label1_position +
            self._xaxis_transform)
        self._theta_label2_position = Affine2D().translate(0.0, 1.0 / 1.1)
        self._xaxis_text2_transform = (
            self._theta_label2_position +
            self._xaxis_transform)

        # This is the transform for r-axis ticks.  It scales the theta
        # axis so the gridlines from 0.0 to 1.0, now go from 0.0 to
        # 2pi.
        self._yaxis_transform = (
            Affine2D().scale(np.pi * 2.0, 1.0) +
            self.transData)
        # The r-axis labels are put at an angle and padded in the r-direction
        self._r_label1_position = Affine2D().translate(22.5, self._rpad)
        self._yaxis_text1_transform = (
            self._r_label1_position +
            Affine2D().scale(1.0 / 360.0, 1.0) +
            self._yaxis_transform
            )
        self._r_label2_position = Affine2D().translate(22.5, self._rpad)
        self._yaxis_text2_transform = (
            self._r_label2_position +
            Affine2D().scale(1.0 / 360.0, 1.0) +
            self._yaxis_transform
            )
コード例 #10
0
ファイル: myplot.py プロジェクト: janfrs/kwc-ros-pkg
    def draw_plot(self):
                if self._doRePlot:
                    self._resizeCreateContent()
                if self.background is None:
                    self.background = self.canvas.copy_from_bbox(self.ax.bbox)
                self.foo += 1
                #self.y = numpy.cos(numpy.arange(0.0,1.0,0.1)+self.foo*0.1)
                # Optimization on the blitting: we compute the box where the changes happen
                changes_box = None

                for i in range(len(self.lines)):
                    data=self.channels[i].getNext()
                    
                    if len(data[1])>0:
                        if self.autolim:
                            print self.autolim[0], data[1], self.autolim[1]
                            self.autolim = [ min(self.autolim[0], min(data[1])), \
                                max(self.autolim[1], max(data[1])) ]
                        else:
                            self.autolim = [ min(data[1]), min(data[1]) ]
                        
                        if changes_box is None:
                            changes_box = Bbox.unit()
                        print '>>>>>>>>'
                        print data[0], data[1]
                        changes_box.update_from_data(numpy.array(data[0]), \
                                numpy.array(data[1]), ignore=changes_box.is_unit())
                        
                        if not self._doRePlot and len(data[0]) > 0 :
                            end = data[0][-1]
                            
                            if end > self.begin+self.span:
                                self.begin += self.span
                                self._doRePlot = True
                                print 'do replot'
                        self.lines[i].set_data(data[0], data[1])
                    else:
                        self.lines[i].set_data([], [])
                
                if not changes_box:
                    return
                #self.canvas.restore_region(self.background)
                for line in self.lines:
                    self.ax.draw_artist(line)
                    #print line.get_transform()
                    tr = line.get_transform()
                    
                changes_box_inframe = changes_box.transformed(tr)
                
                box_padding = 5
                (x,y,l,w) = changes_box_inframe.bounds
                changes_box_inframe = Bbox.from_bounds(x-box_padding, \
                    y-box_padding, l+2*box_padding, w+2*box_padding)
                
                #print 
                t0 = time.time()
                self.canvas.blit(None)
                #self.canvas.blit(changes_box_inframe)
                self.blit_time += time.time() - t0
コード例 #11
0
ファイル: semipolar.py プロジェクト: rflrob/YildizLabCode
    def _set_lim_and_transforms(self):
        self.transAxes = BboxTransformTo(self.bbox)

        # Transforms the x and y axis separately by a scale factor
        # It is assumed that this part will have non-linear components
        self.transScale = TransformWrapper(IdentityTransform())

        # A (possibly non-linear) projection on the (already scaled) data
        self.transProjection = self.PolarTransform()

        # An affine transformation on the data, generally to limit the
        # range of the axes
        self.transProjectionAffine = self.PolarAffine(self.transScale, self.viewLim)

        # The complete data transformation stack -- from data all the
        # way to display coordinates
        self.transData = self.transScale + IdentityTransform() + \
                (self.transProjectionAffine + self.transAxes)
        # old version of the previous line 
        self.transGrid = self.transScale + self.transProjection + \
            (self.transProjectionAffine + self.transAxes)

        # This is the transform for theta-axis ticks.  It is
        # equivalent to transData, except it always puts r == 1.0 at
        # the edge of the axis circle.
        self._xaxis_transform = (
            self.transProjection +
            self.PolarAffine(IdentityTransform(), Bbox.unit()) +
            self.transAxes)
        # The theta labels are moved from radius == 0.0 to radius == 1.1
        self._theta_label1_position = Affine2D().translate(0.0, 1.1)
        self._xaxis_text1_transform = (
            self._theta_label1_position +
            self._xaxis_transform)
        self._theta_label2_position = Affine2D().translate(0.0, 1.0 / 1.1)
        self._xaxis_text2_transform = (
            self._theta_label2_position +
            self._xaxis_transform)

        # This is the transform for r-axis ticks.  It scales the theta
        # axis so the gridlines from 0.0 to 1.0, now go from 0.0 to
        # 2pi.
        self._yaxis_transform = (
            Affine2D().scale(npy.pi * 2.0, 1.0) +
            self.transGrid)
        # The r-axis labels are put at an angle and padded in the r-direction
        self._r_label1_position = Affine2D().translate(22.5, self._rpad)
        self._yaxis_text1_transform = (
            self._r_label1_position +
            Affine2D().scale(1.0 / 360.0, 1.0) +
            self._yaxis_transform
            )
        self._r_label2_position = Affine2D().translate(22.5, self._rpad)
        self._yaxis_text2_transform = (
            self._r_label2_position +
            Affine2D().scale(1.0 / 360.0, 1.0) +
            self._yaxis_transform
            )
コード例 #12
0
    def connect_bbox(bbox1, bbox2, loc1, loc2=None):
        """
        Helper function to obtain a Path from one bbox to another.

        Parameters
        ----------
        bbox1, bbox2 : `matplotlib.transforms.Bbox`
            Bounding boxes to connect.

        loc1 : {1, 2, 3, 4}
            Corner of *bbox1* to use. Valid values are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4

        loc2 : {1, 2, 3, 4}, optional
            Corner of *bbox2* to use. If None, defaults to *loc1*.
            Valid values are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4

        Returns
        -------
        path : `matplotlib.path.Path`
            A line segment from the *loc1* corner of *bbox1* to the *loc2*
            corner of *bbox2*.
        """
        if isinstance(bbox1, Rectangle):
            bbox1 = TransformedBbox(Bbox.unit(), bbox1.get_transform())
        if isinstance(bbox2, Rectangle):
            bbox2 = TransformedBbox(Bbox.unit(), bbox2.get_transform())
        if loc2 is None:
            loc2 = loc1
        x1, y1 = BboxConnector.get_bbox_edge_pos(bbox1, loc1)
        x2, y2 = BboxConnector.get_bbox_edge_pos(bbox2, loc2)
        return Path([[x1, y1], [x2, y2]])
コード例 #13
0
ファイル: cake_plot.py プロジェクト: zackspica/pyrocko
 def _set_lim_and_transforms(self):
     PolarAxes._set_lim_and_transforms(self)
     self.transProjection = self.GlobeCrossSectionTransform(GlobeCrossSectionAxes.RESOLUTION)
     self.transData = self.transScale + self.transProjection + (self.transProjectionAffine + self.transAxes)
     self._xaxis_transform = (
         self.transProjection + self.PolarAffine(IdentityTransform(), Bbox.unit()) + self.transAxes
     )
     self._xaxis_text1_transform = self._theta_label1_position + self._xaxis_transform
     self._yaxis_transform = Affine2D().scale(num.pi * 2.0, 1.0) + self.transData
     self._yaxis_text1_transform = (
         self._r_label1_position + Affine2D().scale(1.0 / 360.0, 1.0) + self._yaxis_transform
     )
コード例 #14
0
ファイル: bovy_plot.py プロジェクト: viveikjha/galpy
 def _set_lim_and_transforms(self):
     PolarAxes._set_lim_and_transforms(self)
     self.transProjection = self.GalPolarTransform()
     self.transData = (self.transScale + self.transProjection +
                       (self.transProjectionAffine + self.transAxes))
     self._xaxis_transform = (self.transProjection + self.PolarAffine(
         IdentityTransform(), Bbox.unit()) + self.transAxes)
     self._xaxis_text1_transform = (self._theta_label1_position +
                                    self._xaxis_transform)
     self._yaxis_transform = (Affine2D().scale(sc.pi * 2.0, 1.0) +
                              self.transData)
     self._yaxis_text1_transform = (self._r_label1_position +
                                    Affine2D().scale(1.0 / 360.0, 1.0) +
                                    self._yaxis_transform)
コード例 #15
0
 def get_size(self):
     factor = 1.
     if self.unit == "points":
         factor = self.ax.figure.dpi / 72.
     elif self.unit[:4] == "axes":
         b = TransformedBbox(Bbox.unit(), self.ax.transAxes)
         dic = {
             "max": max(b.width, b.height),
             "min": min(b.width, b.height),
             "width": b.width,
             "height": b.height
         }
         factor = dic[self.unit[5:]]
     return self.size * factor
コード例 #16
0
 def _set_lim_and_transforms(self):
     PolarAxes._set_lim_and_transforms(self)
     self.transProjection = self.NorthPolarTransform()
     self.transData = (
         self.transScale + 
         self.transProjection + 
         (self.transProjectionAffine + self.transAxes))
     self._xaxis_transform = (
         self.transProjection +
         self.PolarAffine(IdentityTransform(), Bbox.unit()) +
         self.transAxes)
     self._xaxis_text1_transform = (
         self._theta_label1_position +
         self._xaxis_transform)
     self._yaxis_transform = (
         Affine2D().scale(np.pi * 2.0, 1.0) +
         self.transData)
コード例 #17
0
 def _set_lim_and_transforms(self):
     """
     """
     PolarAxes._set_lim_and_transforms(self)
     self.transProjection = self.DipPolarTransform()
     # pylint: attribute-defined-outside-init,invalid-name
     self.transData = (self.transScale + self.transProjection +
                       (self.transProjectionAffine + self.transAxes))
     # pylint: attribute-defined-outside-init,invalid-name
     self._xaxis_transform = (
         self.transProjection +
         self.PolarAffine(IdentityTransform(), Bbox.unit()) + self.transAxes
     )  # pylint: attribute-defined-outside-init
     self._xaxis_text1_transform = (
         self._theta_label1_position + self._xaxis_transform
     )  # pylint: attribute-defined-outside-init
     self._yaxis_transform = (Affine2D().scale(np.pi * 2.0, 1.0) +
                              self.transData
                              )  # pylint: attribute-defined-outside-init
     self._yaxis_text1_transform = (
         Affine2D().scale(1.0 / 360.0, 1.0) + self._yaxis_transform
     )  # pylint: attribute-defined-outside-init
コード例 #18
0
ファイル: polar_axes.py プロジェクト: gbtami/innstereo
 def _set_lim_and_transforms(self):
     """
     """
     PolarAxes._set_lim_and_transforms(self)
     self.transProjection = self.DipPolarTransform()
     # pylint: attribute-defined-outside-init,invalid-name
     self.transData = (
         self.transScale +
         self.transProjection +
         (self.transProjectionAffine + self.transAxes))
     # pylint: attribute-defined-outside-init,invalid-name
     self._xaxis_transform = (
         self.transProjection +
         self.PolarAffine(IdentityTransform(), Bbox.unit()) +
         self.transAxes)  # pylint: attribute-defined-outside-init
     self._xaxis_text1_transform = (
         self._theta_label1_position +
         self._xaxis_transform)  # pylint: attribute-defined-outside-init
     self._yaxis_transform = (
         Affine2D().scale(np.pi * 2.0, 1.0) +
         self.transData)  # pylint: attribute-defined-outside-init
     self._yaxis_text1_transform = (
         Affine2D().scale(1.0 / 360.0, 1.0) +
         self._yaxis_transform)  # pylint: attribute-defined-outside-init
コード例 #19
0
ファイル: wxplot.py プロジェクト: janfrs/kwc-ros-pkg
    def draw_plot(self):
        if self._doRePlot:
            self._resizeCreateContent()
        if self.background is None:
            self.background = self.canvas.copy_from_bbox(self.ax.bbox)
        
        changes_box = None
        #try:
            
        for i in range(len(self.lines)):
            data=self.channels[i].getNext()

            if len(data[0]) > 0:
              if len(data[0]) != len(data[1]):
                print 'incoherent data',  len(data[0]),  len(data[1])
                return
              # Add new points
              #print type(self.cached_datax[i]), type(data[0])
              if isinstance(data[0], numpy.ndarray):
                self.cached_datax[i] += list(data[0])
                self.cached_datay[i] += data[1].tolist()
              else:
                self.cached_datax[i] += data[0]
                self.cached_datay[i] += data[1]
            
            if len(data[1])>0:
                if self.autolim:
                    self.autolim = [ min(self.autolim[0], min(data[1])), \
                        max(self.autolim[1], max(data[1])) ]
                else:
                    self.autolim = [ min(data[1]), min(data[1]) ]
                
                if changes_box is None:
                    changes_box = Bbox.unit()
                changes_box.update_from_data(numpy.array(data[0]), \
                        numpy.array(data[1]), ignore=changes_box.is_unit())
                
                if not self._doRePlot and len(data[0]) > 0 :
                    end = data[0][-1]
                    
                    if end > self.begin+self.span:
                        self.begin = end
                        self._doRePlot = True
                #print 'C'
                #self.cached_datax[i] += (data[0])
                #self.cached_datay[i] += (data[1])
                #print self.cached_datay[i], self.cached_datax[i]
                self.lines[i].set_data(self.cached_datax[i], \
                    self.cached_datay[i])
                #self.lines[i].set_data(data[0], data[1])
            else:
                self.lines[i].set_data([], [])
        
        if not changes_box:
            return
        
        for line in self.lines:
            self.ax.draw_artist(line)
            tr = line.get_transform()
            
        changes_box_inframe = changes_box.transformed(tr)
        
        box_xpadding = 20
        box_ypadding = 100
        (x,y,l,w) = changes_box_inframe.bounds
        changes_box_inframe = Bbox.from_bounds(x-box_xpadding, \
            y-box_ypadding, l+2*box_xpadding, w+2*box_ypadding)
        
        #self.canvas.blit(None)
        self.canvas.blit(changes_box_inframe)
コード例 #20
0
    def draw_plot(self):
        if self._doRePlot:
            self._resizeCreateContent()
        if self.background is None:
            self.background = self.canvas.copy_from_bbox(self.ax.bbox)

        changes_box = None
        #try:

        for i in range(len(self.lines)):
            data = self.channels[i].getNext()

            if len(data[0]) > 0:
                if len(data[0]) != len(data[1]):
                    print 'incoherent data', len(data[0]), len(data[1])
                    return
                # Add new points
                #print type(self.cached_datax[i]), type(data[0])
                if isinstance(data[0], numpy.ndarray):
                    self.cached_datax[i] += list(data[0])
                    self.cached_datay[i] += data[1].tolist()
                else:
                    self.cached_datax[i] += data[0]
                    self.cached_datay[i] += data[1]

            if len(data[1]) > 0:
                if self.autolim:
                    self.autolim = [ min(self.autolim[0], min(data[1])), \
                        max(self.autolim[1], max(data[1])) ]
                else:
                    self.autolim = [min(data[1]), min(data[1])]

                if changes_box is None:
                    changes_box = Bbox.unit()
                changes_box.update_from_data(numpy.array(data[0]), \
                        numpy.array(data[1]), ignore=changes_box.is_unit())

                if not self._doRePlot and len(data[0]) > 0:
                    end = data[0][-1]

                    if end > self.begin + self.span:
                        self.begin = end
                        self._doRePlot = True
                #print 'C'
                #self.cached_datax[i] += (data[0])
                #self.cached_datay[i] += (data[1])
                #print self.cached_datay[i], self.cached_datax[i]
                self.lines[i].set_data(self.cached_datax[i], \
                    self.cached_datay[i])
                #self.lines[i].set_data(data[0], data[1])
            else:
                self.lines[i].set_data([], [])

        if not changes_box:
            return

        for line in self.lines:
            self.ax.draw_artist(line)
            tr = line.get_transform()

        changes_box_inframe = changes_box.transformed(tr)

        box_xpadding = 20
        box_ypadding = 100
        (x, y, l, w) = changes_box_inframe.bounds
        changes_box_inframe = Bbox.from_bounds(x-box_xpadding, \
            y-box_ypadding, l+2*box_xpadding, w+2*box_ypadding)

        #self.canvas.blit(None)
        self.canvas.blit(changes_box_inframe)
コード例 #21
0
def draw_grid(*,
              max_row: int,
              max_column: int,
              clued_locations: Set[Location],
              location_to_entry: Dict[Location, str],
              location_to_clue_numbers: Dict[Location, Sequence[str]],
              top_bars: Set[Location],
              left_bars: Set[Location],
              shading: Dict[Location, str] = {},
              rotation: Dict[Location, str] = {},
              circles: Set[Location] = set(),
              **args: Any) -> None:

    _axes = args.get('axes')
    if _axes:
        axes = cast(Axes, _axes)
    else:
        _, axes = plt.subplots(1, 1, figsize=(8, 11), dpi=100)

    # Set (1,1) as the top-left corner, and (max_column, max_row) as the bottom right.
    axes.axis([1, max_column, max_row, 1])
    axes.axis('equal')
    axes.axis('off')

    # Fill in the shaded squares
    for row, column in itertools.product(range(1, max_row),
                                         range(1, max_column)):
        if (row, column) in shading:
            color = shading[row, column]
            axes.add_patch(
                patches.Rectangle((column, row),
                                  1,
                                  1,
                                  facecolor=color,
                                  linewidth=0))
        # elif (row, column) not in clued_locations:
        #     axes.add_patch(patches.Rectangle((column, row), 1, 1, facecolor='black', linewidth=0))

    for row, column in itertools.product(range(1, max_row + 1),
                                         range(1, max_column + 1)):
        this_exists = (row, column) in clued_locations
        left_exists = (row, column - 1) in clued_locations
        above_exists = (row - 1, column) in clued_locations
        if this_exists or left_exists:
            width = 5 if this_exists != left_exists or (
                row, column) in left_bars else None
            axes.plot([column, column], [row, row + 1],
                      'black',
                      linewidth=width)
        if this_exists or above_exists:
            width = 5 if this_exists != above_exists or (
                row, column) in top_bars else None
            axes.plot([column, column + 1], [row, row],
                      'black',
                      linewidth=width)

        if (row, column) in shading:
            color = shading[row, column]
            axes.add_patch(
                patches.Rectangle((column, row),
                                  1,
                                  1,
                                  facecolor=color,
                                  linewidth=0))

    for row, column in circles:
        circle = plt.Circle((column + .5, row + .5),
                            radius=.4,
                            linewidth=2,
                            fill=False,
                            facecolor='black')
        axes.add_patch(circle)

    scaled_box = Bbox.unit().transformed(axes.transData -
                                         axes.figure.dpi_scale_trans)
    inches_per_data = min(abs(scaled_box.width), abs(scaled_box.height))
    points_per_data = 72 * inches_per_data

    # Fill in the values
    for (row, column), entry in location_to_entry.items():
        axes.text(column + 1 / 2,
                  row + 1 / 2,
                  entry,
                  fontsize=points_per_data / 2,
                  fontweight='bold',
                  fontfamily="sans-serif",
                  verticalalignment='center',
                  horizontalalignment='center',
                  rotation=rotation.get((row, column), 0))

    # Fill in the clue numbers
    for (row, column), clue_numbers in location_to_clue_numbers.items():
        font_info = dict(fontsize=points_per_data / 4, fontfamily="sans-serif")
        for index, text in enumerate(clue_numbers):
            if index == 0:
                axes.text(column + .05,
                          row + .05,
                          text,
                          verticalalignment='top',
                          horizontalalignment='left',
                          **font_info)
            elif index == 1:
                axes.text(column + .95,
                          row + .05,
                          text,
                          verticalalignment='top',
                          horizontalalignment='right',
                          **font_info)
            elif index == 2:
                axes.text(column + .05,
                          row + .95,
                          text,
                          verticalalignment='bottom',
                          horizontalalignment='left',
                          **font_info)
            elif index == 3:
                axes.text(column + .95,
                          row + .95,
                          text,
                          verticalalignment='bottom',
                          horizontalalignment='right',
                          **font_info)

    if not _axes:
        plt.show()