Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (57 sloc) 2.134 kb
b2d7f33 @Ttl Added external plotting for pypy compatibility. Unfilled constraints are...
authored
1 import matplotlib
2 matplotlib.use('Agg')
3 import matplotlib.pyplot as plt
4 from os.path import join as path_join
5 from time import strftime
6
7 def save_plot(v,k,goal_val,sim_type,generation,score,output_path,plot_title=None,yrange=None,log_plot=False,constraints=None,name=''):
8 #For every measurement in results
9 plt.figure()
10 freq = v[0]
11 gain = v[1]
12 if log_plot:#Logarithmic plot
13 plt.semilogx(freq,gain,'g',basex=10)
14 plt.semilogx(freq,goal_val,'b',basex=10)
15 #if self.plot_weight:
16 # plt.semilogx(freq,weight_val,'r--',basex=10)
17 if constraints!=None:
18 plt.plot(*zip(*constraints), marker='.', color='r', ls='')
19 else:
20 plt.plot(freq,gain,'g')
21 plt.plot(freq,goal_val,'b')
22 #if self.plot_weight:
23 # plt.plot(freq,weight_val,'r--')
24 if constraints!=None:
25 plt.plot(*zip(*constraints), marker='.', color='r', ls='')
26
27 # update axis ranges
28 ax = []
29 ax[0:4] = plt.axis()
30 # check if we were given a frequency range for the plot
31 if yrange!=None:
32 plt.axis([min(freq),max(freq),yrange[0],yrange[1]])
33 else:
34 plt.axis([min(freq),max(freq),min(-0.5,-0.5+min(goal_val)),max(1.5,0.5+max(goal_val))])
35
36 if sim_type=='dc':
37 plt.xlabel("Input (V)")
38 if sim_type=='ac':
39 plt.xlabel("Input (Hz)")
40 if sim_type=='tran':
41 plt.xlabel("Time (s)")
42
43 if plot_title!=None:
44 plt.title(plot_title)
45 else:
46 plt.title(k)
47
48 plt.annotate('Generation '+str(generation),xy=(0.05,0.95),xycoords='figure fraction')
49 if score!=None:
50 plt.annotate('Score '+'{0:.2f}'.format(score),xy=(0.75,0.95),xycoords='figure fraction')
51 plt.grid(True)
52 # turn on the minor gridlines to give that awesome log-scaled look
53 plt.grid(True,which='minor')
54 if len(k)>=3 and k[1:3] == 'db':
55 plt.ylabel("Output (dB)")
56 elif k[0]=='v':
57 plt.ylabel("Output (V)")
58 elif k[0]=='i':
59 plt.ylabel("Output (A)")
60
61 plt.savefig(path_join(output_path,strftime("%Y-%m-%d %H:%M:%S")+'-'+k+'-'+str(name)+'.png'))
62
63 data = input()
64 save_plot(*data)
Something went wrong with that request. Please try again.