예제 #1
0
    def __init__(self,
                 blocks,
                 shape=new_shape(Triangle),
                 between_shape=None,
                 strand=None,
                 offset=0,
                 by_axis=None,
                 name=None,
                 **kwargs):
        if type(shape) in (tuple, list):
            self._shape = shape
        else:
            self._shape = [shape]

        if type(between_shape) in (tuple, list, type(None)):
            self._between_shape = between_shape
        else:
            self._between_shape = [between_shape]

        self._blocks = blocks
        self._strand = strand
        self._offset = offset
        self._by_axis = by_axis
        self._name = name

        self._paths = None
        self._patches = None

        Collection.__init__(self, **kwargs)
        self._draw_patches()
        return
예제 #2
0
    def __init__(
            self,
            features,
            width=1,
            offset=0,
            stack=None,
            by_axis=None,
            name=None,
            **kwargs
            ):
        """ . """
        self._features = features
        self._width = width
        self._stack = stack
        self._by_axis = by_axis
        self._offset = offset
        self.name = name

        self._patches = None
        self._paths = None


        Collection.__init__(self, **kwargs)
        self._draw_patches()
        return
예제 #3
0
    def __init__(
            self,
            blocks,
            shape=new_shape(Triangle),
            between_shape=None,
            strand=None,
            offset=0,
            by_axis=None,
            name=None,
            **kwargs
            ):
        if type(shape) in (tuple, list):
            self._shape = shape
        else:
            self._shape = [shape]

        if type(between_shape) in (tuple, list, type(None)):
            self._between_shape = between_shape
        else:
            self._between_shape = [between_shape]

        self._blocks = blocks
        self._strand = strand
        self._offset = offset
        self._by_axis = by_axis
        self._name = name

        self._paths = None
        self._patches = None

        Collection.__init__(self, **kwargs)
        self._draw_patches()
        return
예제 #4
0
    def __init__(self, map, mask, nest=False, **kwargs):
        Collection.__init__(self, **kwargs)
        nside = healpix.npix2nside(len(map))
        # remove the first axes
        verts = pix2tri(nside, mask.nonzero()[0]).reshape(-1, 3, 2)
        c = np.ones((verts.shape[0], verts.shape[1])) * np.repeat(
            map[mask][:, None], 2, axis=0)

        self._verts = verts
        self._shading = 'gouraud'
        self._is_filled = True
        self.set_array(c.reshape(-1))
예제 #5
0
def test_pandas_indexing(pd):
    # Should not fail break when faced with a
    # non-zero indexed series
    index = [11, 12, 13]
    ec = fc = pd.Series(['red', 'blue', 'green'], index=index)
    lw = pd.Series([1, 2, 3], index=index)
    ls = pd.Series(['solid', 'dashed', 'dashdot'], index=index)
    aa = pd.Series([True, False, True], index=index)

    Collection(edgecolors=ec)
    Collection(facecolors=fc)
    Collection(linewidths=lw)
    Collection(linestyles=ls)
    Collection(antialiaseds=aa)
예제 #6
0
파일: heatmap.py 프로젝트: wongfay0207/Cirq
 def _write_annotations(self, mesh: mpl_collections.Collection, ax: plt.Axes) -> None:
     """Writes annotations to the center of cells. Internal."""
     for path, facecolor in zip(mesh.get_paths(), mesh.get_facecolors()):
         # Calculate the center of the cell, assuming that it is a square
         # centered at (x=col, y=row).
         vertices = path.vertices[:4]
         row = int(round(np.mean([v[1] for v in vertices])))
         col = int(round(np.mean([v[0] for v in vertices])))
         annotation = self.annot_map.get((row, col), '')
         if not annotation:
             continue
         face_luminance = relative_luminance(facecolor)
         text_color = 'black' if face_luminance > 0.4 else 'white'
         text_kwargs = dict(color=text_color, ha="center", va="center")
         text_kwargs.update(self.annot_kwargs)
         ax.text(col, row, annotation, **text_kwargs)
예제 #7
0
def test_pandas_indexing():
    try:
        import pandas as pd
    except ImportError:
        raise SkipTest("Pandas not installed")

    # Should not fail break when faced with a
    # non-zero indexed series
    index = [11, 12, 13]
    ec = fc = pd.Series(['red', 'blue', 'green'], index=index)
    lw = pd.Series([1, 2, 3], index=index)
    ls = pd.Series(['solid', 'dashed', 'dashdot'], index=index)
    aa = pd.Series([True, False, True], index=index)

    Collection(edgecolors=ec)
    Collection(facecolors=fc)
    Collection(linewidths=lw)
    Collection(linestyles=ls)
    Collection(antialiaseds=aa)
예제 #8
0
    def __init__(self,
                 features,
                 width=1,
                 offset=0,
                 stack=None,
                 by_axis=None,
                 name=None,
                 **kwargs):
        """ . """
        self._features = features
        self._width = width
        self._stack = stack
        self._by_axis = by_axis
        self._offset = offset
        self.name = name

        self._patches = None
        self._paths = None

        Collection.__init__(self, **kwargs)
        self._draw_patches()
        return
예제 #9
0
    def draw(self, render):
        ax = self.axes
        ms = np.zeros((len(self._sizes), 3, 3))
        ms[:, 0, 0] = self._sizes
        ms[:, 1, 1] = self._sizes
        ms[:, 2, 2] = 1
        self._transforms = ms

        m = ax.transData.get_affine().get_matrix().copy()
        m[:2, 2:] = 0
        self.set_transform(Affine2D(m))

        return Collection.draw(self, render)
예제 #10
0
파일: collection.py 프로젝트: Andor-Z/scpy2
    def draw(self, render):
        ax = self.axes
        ms = np.zeros((len(self._sizes), 3, 3))
        ms[:, 0, 0] = self._sizes
        ms[:, 1, 1] = self._sizes
        ms[:, 2, 2] = 1
        self._transforms = ms

        m = ax.transData.get_affine().get_matrix().copy()
        m[:2, 2:] = 0
        self.set_transform(Affine2D(m))

        return Collection.draw(self, render)
예제 #11
0
def test_collection_set_array():
    vals = [*range(10)]

    # Test set_array with list
    c = Collection()
    c.set_array(vals)

    # Test set_array with wrong dtype
    with pytest.raises(TypeError, match="^Image data of dtype"):
        c.set_array("wrong_input")

    # Test if array kwarg is copied
    vals[5] = 45
    assert np.not_equal(vals, c.get_array()).any()
예제 #12
0
파일: heatmap.py 프로젝트: Alestainer/Cirq
 def _write_annotations(
     self,
     centers_and_annot: List[Tuple[Point, Optional[str]]],
     collection: mpl_collections.Collection,
     ax: plt.Axes,
 ) -> None:
     """Writes annotations to the center of cells. Internal."""
     for (center, annotation), facecolor in zip(centers_and_annot, collection.get_facecolors()):
         # Calculate the center of the cell, assuming that it is a square
         # centered at (x=col, y=row).
         if not annotation:
             continue
         x, y = center
         face_luminance = vis_utils.relative_luminance(facecolor)
         text_color = 'black' if face_luminance > 0.4 else 'white'
         text_kwargs = dict(color=text_color, ha="center", va="center")
         text_kwargs.update(self._config.get('annotation_text_kwargs', {}))
         ax.text(x, y, annotation, **text_kwargs)
예제 #13
0
 def __init__(self, collections, **kwargs):
     Collection.__init__(self, **kwargs)
     self.set_collections(collections)
예제 #14
0
 def __init__(self, **kwargs):
     Collection.__init__(self, **kwargs)
     verts, c = self.get_verts()
     self.set_array(c.reshape(-1))
예제 #15
0
 def __init__(self, **kwargs):
     Collection.__init__(self, **kwargs)
     verts, c = self.get_verts()
     self.set_array(c.reshape(-1))
예제 #16
0
파일: plot.py 프로젝트: SinghN/nutils
 def __init__(self, xy, tri, **kwargs):
   Collection.__init__(self, **kwargs)
   self.xy = xy
   self.tri = tri
   self._facecolors = numpy.zeros([numpy.max(tri)+1,4]) # fully transparent
예제 #17
0
 def draw(self, renderer):
     return Collection.draw(self, renderer)
예제 #18
0
 def draw(self, renderer):
     return Collection.draw(self, renderer)
예제 #19
0
    def draw(self, renderer):
        v = None
        if isSupportedRenderer(renderer):
           self._sort_zpos = None
           renderer.use_gl = True
           glcanvas = get_glcanvas()
           if self.axes is not None:
               tag = self.axes
               trans = self.axes.transAxes
           elif self.figure is not None:
               tag = self.figure
               trans = self.figure.transFigure

           if glcanvas.has_vbo_data(self):
               d = glcanvas.get_vbo_data(self)
               if self._gl_cz:
                    cz = self._gl_facecolordata
               elif self._gl_cz is not None: cz = self._gl_cz
               else: cz = self._gl_3dpath[2]

               if len(d) > 0 and d[0] is not None:
                   if self._update_v:
                       d[0]['v'].need_update = True
                       self._gl_facecolor = self.to_rgba(cz)
                   if self._update_fc:
                       d[0]['fc'].need_update = True
                       self._gl_facecolor = self.to_rgba(cz)
                   if self._update_ec:
                       d[0]['ec'].need_update = True
                       self._gl_edgecolor = self.to_rgba(cz)
                   if self._update_i:
                       d[0]['i'].need_update = True
                   if self._update_a:
                       if 'vertex_id' in d[0] and d[0]['vertex_id'] is not None:
                           d[0]['vertex_id'].need_update = True
               else:
                   self._update_a = False
                   self._update_v = False
                   self._update_fc = False
                   self._update_ec = False
                   self._update_i = False                                      
               # this happens when all surfaces are hidden.
               # if (len(d)) == 0: print('vbo zero length', self.figobj)   
           if self._update_ec or self._update_fc:
               self.update_scalarmappable()

           gc = renderer.new_gc()               
           glcanvas.frame_request(self, trans)
#           renderer.do_stencil_test = self.do_stencil_test
           glcanvas.start_draw_request(self)

           if self._gl_3dpath is not None:
               if isinstance(self._gl_3dpath[4], list):
                   renderer.gl_draw_path_collection(
                          gc, None, self._gl_3dpath,
                          self.get_transforms(), self._gl_offset, None,
                          self._gl_facecolor, self._gl_edgecolor,
                          self._linewidths, self._linestyles,
                          self._antialiaseds, self._urls,
                          self._offset_position,
                          stencil_test = self.do_stencil_test,
                          view_offset = self._gl_voffset,
                          array_idx = self._gl_array_idx)

               else:
                    renderer.gl_draw_path_collection_e(
                        gc, None, self._gl_3dpath,
                        self.get_transforms(), self._gl_offset, None,
                        self._gl_facecolor, self._gl_edgecolor,
                        self._linewidths, self._linestyles,
                        self._antialiaseds, self._urls,
                        self._offset_position,
                        stencil_test = self.do_stencil_test,
                        view_offset = self._gl_voffset,
                        array_idx = self._gl_array_idx,
                        use_pointfill = self._gl_use_pointfill)

#           renderer.do_stencil_test = False
           glcanvas.end_draw_request()
           gc.restore()
           
           self._update_fc = False
           self._update_ec = False
           self._update_v = False
           self._update_i = False
           finish_gl_drawing(glcanvas, renderer, tag, trans)

           renderer.use_gl = False
        else:
           v =  Collection.draw(self, renderer)
        return v