Chem.Draw.mplCanvas

Package Chem :: Package Draw :: Module mplCanvas |
[hide private]
[frames] | no frames]

# Source Code for Module Chem.Draw.mplCanvas

     1  # $Id: mplCanvas.py 634 2008-04-22 03:51:14Z glandrum $
     2  #
     3  #  Copyright (C) 2008 Greg Landrum
     4  #
     5  #   @@ All Rights Reserved  @@
     6  #
     7  from matplotlib.lines import Line2D
     8  from matplotlib.patches import Polygon
     9
    10 -def addCanvasLine(canvas,p1,p2,color=(0,0,0),color2=None,**kwargs):
    11    if color2 and color2!=color:
    12      mp = (p1[0]+p2[0])/2.,(p1[1]+p2[1])/2.
    13      canvas.add_line(Line2D((p1[0],mp[0]),(p1[1],mp[1]),
    14                             color=color,**kwargs))
    15      canvas.add_line(Line2D((mp[0],p2[0]),(mp[1],p2[1]),
    16                             color=color2,**kwargs))
    17    else:
    18      canvas.add_line(Line2D((p1[0],p2[0]),(p1[1],p2[1]),
    19                             color=color,**kwargs))
    20
    21 -def addCanvasText(canvas,text,pos,font,color=(0,0,0),**kwargs):
    22    canvas.annotate(text,(pos[0],pos[1]),color=color,verticalalignment='center',
    23                    horizontalalignment='center',weight=font.weight,
    24                    size=font.size,family=font.face,backgroundcolor="white")
    25
    26 -def addCanvasPolygon(canvas,ps,color=(0,0,0),**kwargs):
    27    canvas.add_patch(Polygon(ps,linewidth=0,facecolor=color))
    28