1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """ Plot.py - Classes for plotting standard impedance plots are defined here.
23
24 TODO: cleanup, redesign and maybe elimination.
25 """
26
27 __all__ = ['ImpedancePlot']
28
29 import numpy
30 import pylab
31
32 LINESTYLES = ('-', '--', '-.', ':', '.', ',', 'o')
33 CUSTOMDASHES = ((None,None), (5,2), (4,2,1,1), (2,2))
34 COLORS = ('blue', 'red', 'green')
35
37 " Class for generating standard impedance plot with pylab "
38 - def __init__(self, title_string, listtoplot, maximalists=None):
39 self.title_string = title_string
40 self.listtoplot = listtoplot
41 self.maximalists = maximalists
42 self.basefilename = self.title_string.replace(" ","")
43 self.pngfilename = self.basefilename + '.png'
44 self.pdffilename = self.basefilename + '.pdf'
45
46 - def plot(self, style='lin', title=True, fsize=(20,12), xlim=(100,4500)):
47 """ Plot the figure.
48
49 You have to do a pylab.show() to see it.
50 """
51 self.fig = pylab.figure(figsize=fsize)
52
53 if style is 'dB':
54 func = lambda x: 20*numpy.log10(x)
55 else:
56 func = lambda x: x
57 i = 0
58 for data in self.listtoplot:
59 f,z,lbl = data
60 lines = pylab.semilogx(f, func(numpy.abs(z)), LINESTYLES[i],
61 color=COLORS[i], label=lbl)
62 lines[0].set_dashes(CUSTOMDASHES[i])
63 i = i+1
64
65 if self.maximalists is not None:
66 for ml in self.maximalists:
67 print ml
68 for f, z in ml:
69 pylab.semilogx([f], func([z]), 'ok')
70
71 if title:
72 pylab.title(self.title_string)
73
74 pylab.xlabel('Frequency [Hz]')
75 if style is 'dB':
76 pylab.ylabel('Normalized impedance (dB): 20log10(Z/Zc)')
77 else:
78 pylab.ylabel('Normalized impedance Z/Zc')
79 pylab.legend()
80 pylab.grid(True)
81 self.fig.axes[0].xaxis.grid(True, which='minor')
82 pylab.xlim(xlim)
83
84 - def save(self, filename=None):
85 """ Save the figure to a file.
86
87 the file name is made from the figure title if not provided.
88 """
89 if filename is None:
90 filename = self.basefilename
91 print 'saving ' + filename
92 pylab.savefig(filename)
93
94
95
96
97