def __init__(self, start_ls, end_ls, y=0, width=0.001, x_offset=0, is_arrow=True, length_includes_head=True, \ head_width=None, head_length=None, shape='full', overhang=0, \ head_starts_at_zero=False,**kwargs): if head_width is None: head_width = 2 * width if head_length is None: head_length = 1 / (2.0 * abs(end_ls[0] - start_ls[0])) distance = abs(end_ls[-1] - start_ls[0]) if length_includes_head: length = distance else: length = distance + head_length no_of_blocks = len(start_ls) if not distance: verts_ls = [] #display nothing if empty else: """ start by drawing horizontal arrow, point (tip of the arrow) at (0,0). the whole arrow sticks on the x-axis (<=0 part) Notice: the XY -coordination is not the usual math coordination system. it's canvas coordination. (0,0) is top left. horizontal is y-axis. vertical is x-axis. start from the last block, reversely to the 1st block """ verts_ls = [] for i in range(no_of_blocks): block_start = start_ls[i] block_end = end_ls[i] verts = [[block_start, width / 2.0 + y], [block_start, -width / 2.0 + y], [block_end, -width / 2.0 + y], [block_end, width / 2.0 + y]] verts_ls.append(verts) PolyCollection.__init__(self, verts_ls, **kwargs)
def __init__(self, ax, *args, **kw): self.ax = ax X, Y, U, V, C = self._parse_args(*args) self.X = X self.Y = Y self.N = len(X) self.scale = kw.pop('scale', None) self.headwidth = kw.pop('headwidth', 3) self.headlength = float(kw.pop('headlength', 5)) self.headaxislength = kw.pop('headaxislength', 4.5) self.minshaft = kw.pop('minshaft', 1) self.minlength = kw.pop('minlength', 1) self.units = kw.pop('units', 'width') self.width = kw.pop('width', None) self.color = kw.pop('color', 'k') self.pivot = kw.pop('pivot', 'tail') kw.setdefault('facecolors', self.color) kw.setdefault('linewidths', (0,)) PolyCollection.__init__(self, None, offsets=zip(X, Y), transOffset=ax.transData, **kw) self.polykw = kw self.set_UVC(U, V, C) self._initialized = False self.keyvec = None self.keytext = None
def __init__(self, start_ls, end_ls, y=0, width=0.001, x_offset=0, is_arrow=True, length_includes_head=True, \ head_width=None, head_length=None, shape='full', overhang=0, \ head_starts_at_zero=False,**kwargs): if head_width is None: head_width = 2 * width if head_length is None: head_length = 1/(2.0 * abs(end_ls[0]-start_ls[0])) distance = abs(end_ls[-1]-start_ls[0]) if length_includes_head: length=distance else: length=distance+head_length no_of_blocks = len(start_ls) if not distance: verts_ls = [] #display nothing if empty else: """ start by drawing horizontal arrow, point (tip of the arrow) at (0,0). the whole arrow sticks on the x-axis (<=0 part) Notice: the XY -coordination is not the usual math coordination system. it's canvas coordination. (0,0) is top left. horizontal is y-axis. vertical is x-axis. start from the last block, reversely to the 1st block """ verts_ls = [] for i in range(no_of_blocks): block_start = start_ls[i] block_end = end_ls[i] verts = [[block_start, width/2.0+y], [block_start, -width/2.0+y], [block_end, -width/2.0+y], [block_end, width/2.0+y]] verts_ls.append(verts) PolyCollection.__init__(self, verts_ls, **kwargs)
def __init__(self, verts, *args, **kwargs): ''' Create a Poly3DCollection. *verts* should contain 3D coordinates. Note that this class does a bit of magic with the _facecolors and _edgecolors properties. ''' PolyCollection.__init__(self, verts, *args, **kwargs) self._zsort = 1 self._sort_zpos = None
def __init__(self, verts, *args, **kwargs): ''' Create a Poly3DCollection. *verts* should contain 3D coordinates. Keyword arguments: zsort, see set_zsort for options. Note that this class does a bit of magic with the _facecolors and _edgecolors properties. ''' zsort = kwargs.pop('zsort', True) PolyCollection.__init__(self, verts, *args, **kwargs) self.set_zsort(zsort)
def __init__(self, map, mask, nest=False, **kwargs): nside = healpix.npix2nside(len(mask)) self.v = pix2quad(nside, mask.nonzero()[0], nest) PolyCollection.__init__(self, self.v, array=map[mask], **kwargs)
def __init__(self, map, mask, nest=False, **kwargs): nside = healpix.npix2nside(len(mask)) self.v, ind = pix2quad(nside, mask.nonzero()[0], nest) #print(len(ind), len(self.v), mask.sum()) PolyCollection.__init__(self, self.v, array=map[ind], **kwargs)
def __init__(self, annotated_box_ls, y=0, width=0.001, linewidths = None, box_line_widths = None, colors = None, antialiaseds = None, linestyle = 'solid', offsets = None, transOffset = None,#transforms.identity_transform(), norm = None, cmap = None, picker=False, pickradius=5, alpha=None, strand=None, facecolors=None, edgecolors=None, rotate_xy=False, \ **kwargs): """ 2008-10-01 block_type='exon' has both facecolor and edgecolor red. block_type='intron' has no facecolor and black edgecolor. arguments edgecolors and facecolors in __init__() could overwrite the ones that generated based on the box_type. 2008-10-01 the annotated_box_ls is a list of (start, stop, box_type, is_translated, ...) box_type = 'exon' or 'intron' and is_translated= 0 or 1. They are optional. Default is box_type ='intron', is_translated=0. 2008-09-26 linewidths controls the width of lines connecting exons or the arrow line, could be a list of floats of just one float. box_line_widths controls the width of the boundaries of exon boxes """ #handle parameters for LineCollection if linewidths is None: linewidths = (mpl.rcParams['lines.linewidth'], ) if box_line_widths is None: box_line_widths = (mpl.rcParams['lines.linewidth'], ) if colors is None: colors = (mpl.rcParams['lines.color'], ) if antialiaseds is None: antialiaseds = (mpl.rcParams['lines.antialiased'], ) self._colors = [ _colors.colorConverter.to_rgba(color, alpha) for color in colors ] #2008-10-26 use to_rgba() instead of to_rgba_list() because the latter is not present in matplotlib 0.98.3 self._aa = self._get_value(antialiaseds) self._lw = self._get_value(linewidths) self.set_linestyle(linestyle) self._uniform_offsets = None if offsets is not None: offsets = asarray(offsets) if len(offsets.shape) == 1: offsets = offsets[numpy.newaxis, :] # Make it Nx2. if transOffset is None: if offsets is not None: self._uniform_offsets = offsets offsets = None if hasattr(transforms, 'identity_transform'): transOffset = transforms.identity_transform( ) #matplotlib 0.91.2 elif hasattr(transforms, 'IdentityTransform'): transOffset = transforms.IdentityTransform( ) #matplotlib 0.98.3 self._offsets = offsets self._transOffset = transOffset self.pickradius = pickradius #handle parameters for PolyCollection verts_ls = [] segment_ls = [] no_of_blocks = len(annotated_box_ls) verts_colors = [] _edgecolors = [] for i in range(no_of_blocks): this_block = annotated_box_ls[i] block_start, block_end = this_block[:2] block_type = 'intron' is_translated = 0 if len(this_block) >= 3: block_type = this_block[2] if len(this_block) >= 4: is_translated = int(this_block[3]) if block_type == 'exon': verts = [[block_start, width / 2.0 + y], [block_start, -width / 2.0 + y], [block_end, -width / 2.0 + y], [block_end, width / 2.0 + y]] if rotate_xy: verts = [[row[1], row[0]] for row in verts] verts_ls.append(verts) if is_translated == 1: verts_colors.append('r') _edgecolors.append('r') #same edge color else: verts_colors.append('w') #no face color _edgecolors.append('k') else: if rotate_xy: segment_ls.append([(y, block_start), (y, block_end)]) else: segment_ls.append([(block_start, y), (block_end, y)]) if not facecolors: facecolors = verts_colors if not edgecolors: edgecolors = _edgecolors #add an arrow box_start = annotated_box_ls[0][0] box_end = annotated_box_ls[-1][1] if strand is not None: arrow_length = abs(box_start - box_end) / 4 try: strand = int(strand) except: pass if strand == 1 or strand == 'plus': arrow_offset = -arrow_length arrow_end = box_end elif strand == -1 or strand == 'minus': arrow_offset = arrow_length arrow_end = box_start else: #can't tell which strand arrow_offset = 0 arrow_end = box_end if rotate_xy: segment_ls.append([(y + width, arrow_end + arrow_offset), (y + width / 2.0, arrow_end)]) else: segment_ls.append([(arrow_end + arrow_offset, y + width), (arrow_end, y + width / 2.0)]) self._segments = segment_ls self.set_segments(segment_ls) self._verts = verts #self.set_alpha(alpha) PolyCollection.__init__(self, verts_ls, linewidths=box_line_widths, antialiaseds=antialiaseds, edgecolors=edgecolors, **kwargs) self._facecolors = [ _colors.colorConverter.to_rgba(facecolor, alpha=alpha) for facecolor in facecolors ] #in PolyCollection.__init__(), it doesn't handle alpha self._picker = picker #to enable picker_event. PolyCollection's ancestor PatchCollection (collection.py) defines a method 'contains()'. #Artist.pick() (in artist.py) calls pickable(), which checks self._picker, first to see whether this artist is pickable. then it calls picker() or contains(). self.update(kwargs)
def __init__(self, annotated_box_ls, y=0, width=0.001, linewidths = None, box_line_widths = None, colors = None, antialiaseds = None, linestyle = 'solid', offsets = None, transOffset = None,#transforms.identity_transform(), norm = None, cmap = None, picker=False, pickradius=5, alpha=None, strand=None, facecolors=None, edgecolors=None, rotate_xy=False, \ **kwargs): """ 2008-10-01 block_type='exon' has both facecolor and edgecolor red. block_type='intron' has no facecolor and black edgecolor. arguments edgecolors and facecolors in __init__() could overwrite the ones that generated based on the box_type. 2008-10-01 the annotated_box_ls is a list of (start, stop, box_type, is_translated, ...) box_type = 'exon' or 'intron' and is_translated= 0 or 1. They are optional. Default is box_type ='intron', is_translated=0. 2008-09-26 linewidths controls the width of lines connecting exons or the arrow line, could be a list of floats of just one float. box_line_widths controls the width of the boundaries of exon boxes """ #handle parameters for LineCollection if linewidths is None : linewidths = (mpl.rcParams['lines.linewidth'], ) if box_line_widths is None : box_line_widths = (mpl.rcParams['lines.linewidth'], ) if colors is None : colors = (mpl.rcParams['lines.color'],) if antialiaseds is None : antialiaseds = (mpl.rcParams['lines.antialiased'], ) self._colors = [_colors.colorConverter.to_rgba(color, alpha) for color in colors] #2008-10-26 use to_rgba() instead of to_rgba_list() because the latter is not present in matplotlib 0.98.3 self._aa = self._get_value(antialiaseds) self._lw = self._get_value(linewidths) self.set_linestyle(linestyle) self._uniform_offsets = None if offsets is not None: offsets = npy.asarray(offsets) if len(offsets.shape) == 1: offsets = offsets[npy.newaxis,:] # Make it Nx2. if transOffset is None: if offsets is not None: self._uniform_offsets = offsets offsets = None if hasattr(transforms, 'identity_transform'): transOffset = transforms.identity_transform() #matplotlib 0.91.2 elif hasattr(transforms, 'IdentityTransform'): transOffset = transforms.IdentityTransform() #matplotlib 0.98.3 self._offsets = offsets self._transOffset = transOffset self.pickradius = pickradius #handle parameters for PolyCollection verts_ls = [] segment_ls = [] no_of_blocks = len(annotated_box_ls) verts_colors = [] _edgecolors = [] for i in range(no_of_blocks): this_block = annotated_box_ls[i] block_start, block_end = this_block[:2] block_type = 'intron' is_translated = 0 if len(this_block)>=3: block_type = this_block[2] if len(this_block)>=4: is_translated = int(this_block[3]) if block_type=='exon': verts = [[block_start, width/2.0+y], [block_start, -width/2.0+y], [block_end, -width/2.0+y], [block_end, width/2.0+y]] if rotate_xy: verts = [[row[1], row[0]] for row in verts] verts_ls.append(verts) if is_translated==1: verts_colors.append('r') _edgecolors.append('r') #same edge color else: verts_colors.append('w') #no face color _edgecolors.append('k') else: if rotate_xy: segment_ls.append([(y, block_start), (y, block_end)]) else: segment_ls.append([(block_start, y), (block_end,y)]) if not facecolors: facecolors = verts_colors if not edgecolors: edgecolors = _edgecolors #add an arrow box_start = annotated_box_ls[0][0] box_end = annotated_box_ls[-1][1] if strand is not None: arrow_length = abs(box_start-box_end)/4 try: strand = int(strand) except: pass if strand==1 or strand=='plus': arrow_offset = -arrow_length arrow_end = box_end elif strand==-1 or strand=='minus': arrow_offset = arrow_length arrow_end = box_start else: #can't tell which strand arrow_offset = 0 arrow_end = box_end if rotate_xy: segment_ls.append([( y+width, arrow_end+arrow_offset), (y+width/2.0, arrow_end)]) else: segment_ls.append([(arrow_end+arrow_offset, y+width), (arrow_end,y+width/2.0)]) self._segments = segment_ls self.set_segments(segment_ls) self._verts = verts #self.set_alpha(alpha) PolyCollection.__init__(self, verts_ls, linewidths=box_line_widths, antialiaseds=antialiaseds, edgecolors=edgecolors, **kwargs) self._facecolors = [_colors.colorConverter.to_rgba(facecolor, alpha=alpha) for facecolor in facecolors] #in PolyCollection.__init__(), it doesn't handle alpha self._picker = picker #to enable picker_event. PolyCollection's ancestor PatchCollection (collection.py) defines a method 'contains()'. #Artist.pick() (in artist.py) calls pickable(), which checks self._picker, first to see whether this artist is pickable. then it calls picker() or contains(). self.update(kwargs)