Skip to content

Commit

Permalink
Added new elements. Changed examples & docs to SVG graphics. Other mi…
Browse files Browse the repository at this point in the history
…nor drawing tweaks.
Collin Delker committed Apr 30, 2015
1 parent 64c293f commit e89c416
Showing 90 changed files with 42,660 additions and 1,637 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -13,3 +13,12 @@ v0.1.4, 09/30/2014
- Add blackbox() function to generate box elements with arbitrary inputs
- Allow element definition to specify label alignment
- Added linestyle to element kwargs and definition

v0.2.0 04/29/2015
- Added elements:
BATTERY, BAT_CELL, SPEAKER, BUTTON, BUTTON_NC, XTAL, MEMRISTOR,
SCHOTTKY, ZENER, LED2
- Added default line width argument to drawing() class. Default width is now 1.5.
- Converted documentation to use all vector-based images
- Added XKCD-mode example

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 Collin J. Delker
Copyright (c) 2014-2015 Collin J. Delker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
75 changes: 39 additions & 36 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -10,45 +10,48 @@ SchemDraw/logic.py
SchemDraw/schemdraw.py
docs/SchemDraw.html
docs/SchemDraw.md
docs/img/2term.png
docs/img/555blinker.png
docs/img/JK.png
docs/img/SR-Latch.png
docs/img/SR_latch_gate.png
docs/img/TL.png
docs/img/and_inputnot.png
docs/img/bjt.png
docs/img/bjt_anchors.png
docs/img/cap-charge.png
docs/img/cap-net.png
docs/img/connectors.png
docs/img/2term.svg
docs/img/555blinker.svg
docs/img/JK.svg
docs/img/SR-Latch.svg
docs/img/SR_latch_gate.svg
docs/img/TL.svg
docs/img/and_inputnot.svg
docs/img/bjt.svg
docs/img/bjt_anchors.svg
docs/img/buttons.svg
docs/img/cap-charge.svg
docs/img/cap-net.svg
docs/img/connectors.svg
docs/img/doc_images.ipynb
docs/img/ex01.png
docs/img/ex03.png
docs/img/ex04.png
docs/img/ex01.svg
docs/img/ex03.svg
docs/img/ex04.svg
docs/img/ex_xkcd.png
docs/img/examples.ipynb
docs/img/fet.png
docs/img/fet_anchors.png
docs/img/full_add.png
docs/img/fulladd_blackbox.png
docs/img/gates.png
docs/img/grounds.png
docs/img/half_add.png
docs/img/inv_opamp.png
docs/img/label.png
docs/img/label_positions.png
docs/img/labeli.png
docs/img/fet.svg
docs/img/fet_anchors.svg
docs/img/full_add.svg
docs/img/fulladd_blackbox.svg
docs/img/gates.svg
docs/img/grounds.svg
docs/img/half_add.svg
docs/img/inv_opamp.svg
docs/img/label.svg
docs/img/label_positions.svg
docs/img/labeli.svg
docs/img/logicgate_images.ipynb
docs/img/loopi.png
docs/img/meters.png
docs/img/nots.png
docs/img/opamp.png
docs/img/opamp_anchor.png
docs/img/pot.png
docs/img/smu.png
docs/img/sources.png
docs/img/switches.png
docs/img/testschematic.png
docs/img/loopi.svg
docs/img/meters.svg
docs/img/nots.svg
docs/img/opamp.svg
docs/img/opamp_anchor.svg
docs/img/pot.svg
docs/img/smu.svg
docs/img/sources.svg
docs/img/speaker.svg
docs/img/switches.svg
docs/img/testschematic.svg
docs/img/.ipynb_checkpoints/doc_images-checkpoint.ipynb
docs/img/.ipynb_checkpoints/examples-checkpoint.ipynb
docs/img/.ipynb_checkpoints/logicgate_images-checkpoint.ipynb
123 changes: 110 additions & 13 deletions SchemDraw/elements.py
Original file line number Diff line number Diff line change
@@ -87,7 +87,12 @@
RES_VAR = {
'name' : 'RES_VAR',
'base' : RES,
'paths' : [ [[.5*_rw,-_rh*3],[5.5*_rw,_rh*3],[4.*_rw,2.5*_rh],_gap,[5.5*_rw,_rh*3],[5.8*_rw,1.9*_rh]] ]
'shapes' : [ { 'shape' : 'arrow',
'start' : [1.5*_rw,-_rh*2],
'end' : [4.5*_rw,_rw*3.5],
'headwidth' : .12,
'headlength' : .2 } ],
'paths' : [ [[1.5*_rw,-_rh*2],[4.5*_rw,_rw*3.5]] ]
}

RBOX = {
@@ -107,21 +112,21 @@
'anchors' : { 'tap' : [_rw*3,_rw*1.5] }
}

_cap_gap = 0.2
_cap_gap = 0.18
CAP = { # Straight capacitor
'name' : 'CAP',
'paths' : [ [[0,0],[0,_rh],[0,-_rh],_gap,[_cap_gap,_rh],[_cap_gap,-_rh],[_cap_gap,0]] ],
'paths' : [ [[0,0],_gap,[0,_rh],[0,-_rh],_gap,[_cap_gap,_rh],[_cap_gap,-_rh],_gap,[_cap_gap,0]] ],
}

CAP_P = { # Polarized
'name' : 'CAP_P',
'base' : CAP,
'labels' : [ {'label':'+', 'pos':[-_cap_gap,_cap_gap]} ]
'labels' : [ {'label':'+', 'pos':[-_cap_gap*1.2,_cap_gap]} ]
}

CAP2 = { # Curved capacitor
'name' : 'CAP2',
'paths' : [ [[0,0],[0,_rh],[0,-_rh],_gap,[_cap_gap,0]] ],
'paths' : [ [[0,0],_gap,[0,_rh],[0,-_rh],_gap,[_cap_gap,0]] ],
'shapes' : [ { 'shape' : 'arc',
'center' :[(_cap_gap*1.5),0],
'theta1' : 120,
@@ -133,9 +138,17 @@
CAP2_P = { # Polarized
'name' : 'CAP2_P',
'base' : CAP2,
'labels' : [ {'label':'+', 'pos':[-_cap_gap,_cap_gap]} ]
'labels' : [ {'label':'+', 'pos':[-_cap_gap*1.2,_cap_gap]} ]
}

_cap_gap = 0.2
XTAL = { # Crystal
'name' : 'XTAL',
'paths' : [ [[0,0],_gap,[0,_rh],[0,-_rh],_gap,
[_cap_gap/2,_rh],[_cap_gap/2,-_rh],[_cap_gap*1.5,-_rh],[_cap_gap*1.5,_rh],[_cap_gap/2,_rh],_gap,
[_cap_gap*2,_rh],[_cap_gap*2,-_rh],_gap,[_cap_gap*2,0]],
],
}

DIODE = {
'name' : 'DIODE',
@@ -154,22 +167,106 @@
'fill' : True } ]
}

_sd = .1
SCHOTTKY = { # Schottky diode
'name' : 'SCHOTTKY',
'base' : DIODE,
'paths' : [ [[_rh*1.4,_rh], [_rh*1.4-_sd,_rh], [_rh*1.4-_sd,_rh-_sd]],
[[_rh*1.4,-_rh], [_rh*1.4+_sd,-_rh], [_rh*1.4+_sd,-_rh+_sd]] ]
}

SCHOTTKY_F = {
'name' : 'SCHOTTKY_F',
'base' : DIODE_F,
'paths' : [ [[_rh*1.4,_rh], [_rh*1.4-_sd,_rh], [_rh*1.4-_sd,_rh-_sd]],
[[_rh*1.4,-_rh], [_rh*1.4+_sd,-_rh], [_rh*1.4+_sd,-_rh+_sd]] ]
}

ZENER = { # Zener diode
'name' : 'ZENER',
'base' : DIODE,
'paths' : [ [[_rh*1.4,_rh], [_rh*1.4+_sd,_rh+_sd]],
[[_rh*1.4,-_rh], [_rh*1.4-_sd,-_rh-_sd]] ]
}

ZENER_F = {
'name' : 'ZENER_F',
'base' : DIODE_F,
'paths' : [ [[_rh*1.4,_rh], [_rh*1.4+_sd,_rh+_sd]],
[[_rh*1.4,-_rh], [_rh*1.4-_sd,-_rh-_sd]] ]
}

LED = {
'name':'LED',
'base':DIODE,
'paths' : [[[_rh,_rh*1.5],[_rh*2,_rh*3.25]]], # Duplicate arrow with a path to work around matplotlib autoscale bug.
'shapes':[ { 'shape':'arrow',
'start': [_rh,_rh*1.5],
'end' : [_rh*2,_rh*3.25],
'headwidth' : .17,
'headwidth' : .12,
'headlength' : .2 },

{ 'shape':'arrow',
'start': [_rh*.1,_rh*1.5],
'end' : [_rh*1.1,_rh*3.25],
'headwidth' : .17,
'headwidth' : .12,
'headlength' : .2 }, ]
}

# LED with squiggle light
x = _np.linspace(-1,1)
y = -x*(x-.7)*(x+.7)/2 + _rh*2.5
x = _np.linspace(_rh*.75,_rh*1.25)
theta = 20
c = _np.cos( _np.radians(theta) )
s = _np.sin( _np.radians(theta) )
m = _np.array( [[c,s],[-s,c]] )
p = _np.transpose(_np.vstack((x,y)))
p = _np.dot( p, m )
p2 = _np.transpose(_np.vstack((x-.2,y)))
p2 = _np.dot( p2, m )
LED2 = {
'name' : 'LED2',
'base' : DIODE,
'paths' : [p,p2],
'shapes' : [ {'shape':'arrow',
'start' : p[1],
'end' : p[0],
'headwidth' : .07,
'headlength' : .08
},
{'shape':'arrow',
'start' : p2[1],
'end' : p2[0],
'headwidth' : .07,
'headlength' : .08
} ]
}


_mr = 0.2
MEMRISTOR = {
'name' : 'MEMRISTOR',
'paths' : [ [[0,_mr*1.25],[_mr*5,_mr*1.25],[_mr*5,_mr*-1.25],[0,_mr*-1.25],[0,_mr*1.25]],
[[0,0],[_mr,0],[_mr,-_mr*.75],[_mr*2,-_mr*.75],[_mr*2,_mr*.75],[_mr*3,_mr*.75],[_mr*3,-_mr*.75],[_mr*4,-_mr*.75],[_mr*4,0],[_mr*5,0]],
],
'shapes' : [ {'shape':'poly',
'xy' : [[0,_mr*1.25],[0,-_mr*1.25],[_mr/2,-_mr*1.25],[_mr/2,_mr*1.25] ],
'fill' : True
}
]
}

_mrv = .25
MEMRISTOR2 = {
'name' : 'MEMRISTOR2',
'paths' : [ [[0,0],[0,_mrv],[_mr,_mrv],[_mr,-_mrv],[_mr*2,-_mrv],[_mr*2,_mrv],
[_mr*3,_mrv],[_mr*3,-_mrv],[_mr*4,-_mrv],[_mr*4,_mrv],
[_mr*5,_mrv],[_mr*5,-_mrv],[_mr*6,-_mrv],[_mr*6,0],
[_mr*7,0]],

],
}


# Connection dots, lines
_dotr = .075
@@ -721,11 +818,11 @@
_x = (_x - _x[0]) # Scale to about the right size
_x = _x / _x[-1]
_y = (_y - _y[0]) * .25
_bulb_path = _np.transpose(_np.vstack((_x,_y)))
BULB = {
'name' : 'BULB',
_lamp_path = _np.transpose(_np.vstack((_x,_y)))
LAMP = {
'name' : 'LAMP',
'base' : SOURCE,
'paths': [_bulb_path]
'paths': [_lamp_path]
}


18 changes: 10 additions & 8 deletions SchemDraw/schemdraw.py
Original file line number Diff line number Diff line change
@@ -106,14 +106,16 @@ def group_elements( drawing, anchors={} ):
# Main drawing class
#--------------------------------------------------------------------
class Drawing():
def __init__(self, unit=3.0, inches_per_unit=0.5, txtofst=0.1, fontsize=16, font='sans-serif', color='black'):
def __init__(self, unit=3.0, inches_per_unit=0.5, txtofst=0.1, fontsize=16, font='sans-serif', color='black', lw=1.5):
""" Set up a new circuit drawing.
unit : Full length of a resistor element in matplotlib plot units.
Inner portion of resistor is length 1.
inches_per_unit : inches per unit to scale drawing.
txtofst : Default distance from element to text label
fontsize : Default font size
font : matplotlib font-family
color : default color for elements
lw : default line width
"""

# Default values
@@ -123,7 +125,7 @@ def __init__(self, unit=3.0, inches_per_unit=0.5, txtofst=0.1, fontsize=16, font
self.fontsize = fontsize
self.font = font
self.color = color
self.lw = 1
self.lw = lw

# State variables
self.here = np.array([0,0])
@@ -204,12 +206,13 @@ def draw(self, ax=None, showframe=False):
if ax==None:
fig, ax = plt.subplots()
else:
fig = ax.gcf()
fig = ax.get_figure()

for e in self._elm_list:
e.draw(ax)

ax.autoscale_view(True) # This autoscales all the shapes too
# NOTE: arrows don't seem to be included in autoscale!
xlim = np.array(ax.get_xlim())
ylim = np.array(ax.get_ylim())
xlim[0] = xlim[0]-.1 # Add a .1 unit border to pick up lost pixels
@@ -236,7 +239,6 @@ def draw(self, ax=None, showframe=False):
ax.get_figure().set_size_inches( self.inches_per_unit*w, self.inches_per_unit*h )



def save(self, fname, transparent=True, dpi=72 ):
""" Save figure to file.
fname : filename to save.
@@ -717,7 +719,7 @@ def draw(self, ax, showframe=False):
fill = s.get('fill', False)
fillcolor = s.get('fillcolor', self.color)
circ = plt.Circle( xy=xy, radius=rad, ec=self.color,
fc=fillcolor, fill=fill, zorder=3 )
fc=fillcolor, fill=fill, zorder=3, lw=self.lw )
ax.add_patch(circ)
elif s.get('shape') == 'poly':
xy = np.array(s.get('xy', [[0,0]]))
@@ -726,7 +728,7 @@ def draw(self, ax, showframe=False):
fill = s.get('fill', False)
fillcolor = s.get('fillcolor', self.color)
poly = plt.Polygon( xy=xy, closed=closed, ec=self.color,
fc=fillcolor, fill=fill, zorder=3 )
fc=fillcolor, fill=fill, zorder=3, lw=self.lw )
ax.add_patch(poly)
elif s.get('shape') == 'arc':
xy = np.array(s.get('center', [0,0] ) )
@@ -740,7 +742,7 @@ def draw(self, ax, showframe=False):

angle = s.get('angle', self.theta )
arc = Arc( xy, width=w, height=h, theta1=th1,
theta2=th2, angle=angle, color=self.color )
theta2=th2, angle=angle, color=self.color, lw=self.lw )
ax.add_patch(arc)

# Add an arrowhead to the arc
@@ -777,7 +779,7 @@ def draw(self, ax, showframe=False):
hl = s.get('headlength', .2 )
ax.arrow(start[0], start[1], end[0]-start[0], end[1]-start[1],
head_width=hw, head_length=hl,
length_includes_head=True, color=self.color)
length_includes_head=True, color=self.color, lw=self.lw)

for label, loc, align, size in self.strs:
loc = self.translate( np.array(loc) )
Loading
Oops, something went wrong.

0 comments on commit e89c416

Please sign in to comment.