-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnpn.py
More file actions
33 lines (26 loc) · 802 Bytes
/
Copy pathnpn.py
File metadata and controls
33 lines (26 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Plot the output characteristics for the BC337 NPN transistor
"""
import ngspyce
import numpy as np
from matplotlib import pyplot as plt
# Load netlist
ngspyce.source('npn.net')
# Sweep both base and collector current
ngspyce.cmd('dc vcc 0 2 .02 vbb .7 1.2 .1')
# Load simulation results into numpy arrays
vb, vc, Ivcc = map(ngspyce.vector, ['Vb', 'Vc', 'I(Vcc)'])
# Correct the sign for collector current
ic = -Ivcc
plt.figure()
# Plot one line per base voltage
series = np.unique(vb)
for _vb in series:
plt.plot(vc[vb == _vb], ic[vb == _vb], '-',
label='Vb = {:.1f}'.format(_vb))
plt.legend(loc='center right')
plt.title('Output characteristics for BC337')
plt.xlabel('Collector-emitter voltage [V]')
plt.ylabel('Collector current [A]')
plt.savefig('bc337.png')
plt.show()