Пример #1
0
  def draw_fg(self,ax, artists,**kwargs):

    qdraw = kwargs.get('qdraw',False)
    if qdraw:
        if len(artists) == 0:
          artists.append(ax.add_collection(lc([zeros((2,2)),zeros((2,2))])))
        self.draw_elements(artists[0],self.bert,
                           n = self.ndraw, 
                           score_cutoff = 1)
    else:
      
      elts, addresses = self.getDrawElements()
      for i in range(len(elts)) :
        e, address = elts[i], list(addresses[i])
        fracs =[self.fracForElement(e,address, 'start'),
                self.fracForElement(e,address, 'end')]
        verts = self.bert.vertices(fracs[0], fracs[1],
                                   snap =False)
        artists[0] = ax.plot(verts[:,0],verts[:,1],
                             color = self.colorfun(e),
                             alpha = self.alphafun(e),
                             zorder= self.zfun(e),
                             linewidth = self.widthfun(e))


    skeleton = kwargs.get('skeleton',-1)
    if not self.skeleton:
      self.skeleton = h.Hilbert(skeleton, self.angle)

    if skeleton != -1:
      skel = self.skeleton
      if kwargs.get('skeloff', 0):
        u = skel.units[1:] * skel.step
        n = array([-u[:,1].T, u[:,0].T]).T
        v = skel.curve[:-1] + n * kwargs.get('skeloff') + u / 2

      else:
        v = skel.vertices(0,1.)

      splot = ax.plot(v[:,0], v[:,1],
                zorder = -1,
                linewidth = kwargs.get('skelwidth', 1), 
                alpha = kwargs.get('skelalpha',1),
                color = 'black')
      if len(artists) == 1:
        artists.append(splot[0])
      else:
        artists[1] = splot[0]
        
    ax.set_xticks([])
    ax.set_yticks([])
Пример #2
0
  def preview_zoom(self, 
                   axes, artists,
                   frac_start,frac_end,
                   **kwargs):

    #FIRST GET XY COORDINATES FOR THE PREVIEW ENDS
    if self.select_skeleton:
      bert = self.skeleton
    else:
      bert = self.bert
    ptstart = bert.map(frac_start)
    ptend = bert.map(frac_end)


    import matplotlib.lines as l

    refined = h.Hilbert(kwargs.get('lvl',4),kwargs.get('angle',90),
                        start= ptstart,
                        finish =ptend)
    verts = refined.vertices(0,1)
    
    if artists == None or len(artists) == 0:
      artists = [axes.plot(verts.T, 
                               linewidth =  40, color = 'white', alpha = .9)[0]]
    else:
      artists[0].set_xdata(verts[:,0])
      artists[0].set_ydata(verts[:,1])

    if len(artists) < 2:
      artists.append(axes.add_collection(lc((verts, verts))))
    

    #global_draw_scope:
    draw_scope = [self.globalFrac(frac_start),self.globalFrac(frac_end)]
    self.draw_elements(artists[1],
                       refined,
                       [frac_start, frac_end], #coordinates in the local scope
                       draw_scope  = draw_scope,
                       n = 200, 
                       score_cutoff = 1)

    


    return artists
Пример #3
0
def plot_graph(g, x, y, color='b', directed=0):
    """
    plot the graph represented by the adjacency matrix g
    """
    from matplotlib import pyplot as plt
    from matplotlib.collections import LineCollection as lc

    plt.plot(x, y, '.' + color)

    p = _np.concatenate((x[:, None], y[:, None]), axis=1)
    L = p[_np.array(g.nonzero()).T]

    if directed > 0:
        p2 = L[:, 0, :] + (L[:, 1] - L[:, 0]) * directed
        plt.plot(p2[:, 0], p2[:, 1], '.' + color)

    lines = lc(L, color=color)
    plt.gca().add_collection(lines)
Пример #4
0
def draw(graph, pos,edges,
         labels = None,
         scatter_nodes = None,
         ckw = {},     #CONNECTION STYLE KWS
         skw = {},
         cktype = 'pretty',
         ckalpha = 1):    #SKATTERPLOT KWS):
    '''
Draw a graph with scatterpoint keyword given in skw
and connectionpoint keyworks given by ckw.

ckw:
  ckw takes the form of a dictionary; edges lacking a key in ckw
  will not be plotted. For every edges that is plotted, the following
  keywords are allowed:

  'alpha'
  'fc'
  'ec'

  skw:
  see pyplot.scatter?

'''
    #MATPLOTLIB ARROW TYPES
    '''
-	None
->	head_length=0.4,head_width=0.2
-[	widthB=1.0,lengthB=0.2,angleB=None
-|>	head_length=0.4,head_width=0.2
<-	head_length=0.4,head_width=0.2
<->	head_length=0.4,head_width=0.2
<|-	head_length=0.4,head_width=0.2
<|-|>	head_length=0.4,head_width=0.2
fancy	head_length=0.4,head_width=0.4,tail_width=0.4
simple	head_length=0.5,head_width=0.5,tail_width=0.2
wedge	tail_width=0.3,shrink_factor=0.5
'''
    #cstr = "arc3,rad="+'.2'#str(-(i - nt/2) *.2)

    if scatter_nodes == None:
        scatter_nodes = graph.nodes()

    ax = plt.gca()
    
    if cktype != 'simple':    
        for i, e in enumerate(edges):
            if e in ckw:
                ax.annotate('', xy=pos[e[1]],  xycoords='data',
                            xytext=pos[e[0]], textcoords='data',
                            arrowprops=dict( 
                        #connectionstyle=cstr,
                        #shrinkA=10,shrinkB = 10,
                        **ckw.get(e,{})  ),
                            )
    else:
        lines = [ (pos[e[0]],pos[e[1]])
                  for e in edges]
        colors = [ckw.get(e,{}).get('color', [0,0,0,1] ) for e in  edges]
        linewidths=[ckw.get(e,{}).get('linewidth',1) for e in edges]
        ax.add_collection(lc( lines, colors = colors, linewidths = linewidths,
                              alpha = ckalpha))
        
    
    #return
    xys  = [pos[n] for n in scatter_nodes]
    if xys:
        ax.scatter(*zip(*xys), **skw)