def Execute(self, namespace, figfolder='figs',\ def_ext='.png', dpi=100, **kwargs): if not os.path.exists(figfolder): os.mkdir(figfolder) python_report_env.Execute(self, namespace=namespace, **kwargs) keys = ['caption','filename','label'] mypat = '^#('+'|'.join(keys)+')' comments = [item for item in self.list if item.find('#')==0] if comments[0].find('#pyfig') == 0: comments.pop(0) com_list = txt_mixin.txt_list(comments) start_inds = com_list.findallre(mypat) end_inds = start_inds[1:]+[None] pat2 = '^#('+'|'.join(keys)+')'+':(.*)' p2 = re.compile(pat2) keysfound = [] for si, ei in zip(start_inds, end_inds): chunk = ''.join(com_list[si:ei]) q2 = p2.match(chunk) if q2: key = q2.group(1) body = q2.group(2) body = body.replace('#',' ') setattr(self, key, body) keysfound.append(key) assert 'filename' in keysfound, "#filename: was not found in " + \ self.code +'\n'*2+ \ 'NOTE: it must be in the beginning comments.' fno, ext = os.path.splitext(self.filename) if not ext: ext = def_ext self.nameout = fno+ext self.pathout = os.path.join(figfolder, self.nameout) PU.mysave(self.pathout, dpi=dpi)
def _save_figs(filenames, startfi=1, del_eps=True): fis = range(startfi, startfi+NF) for fi, fname in zip(fis, filenames): epsname = fname+'.eps' outpath = os.path.join(figdir, epsname) PU.mysave(outpath, fi=fi) if del_eps: os.remove(outpath)#delete eps but leave pdf
def Save(self, pathout=None, fignum=None, ext='.eps'): if fignum is None: fignum = self.fignum if pathout is None: pathout = self._find_filename(ext=ext) else: self.pathout = pathout pylab_util.mysave(pathout, fignum)
def save_figs(self, basename, startfi=1, del_eps=True): endings = ['th_v_bode','a_v_bode','a_th_bode'] filenames = [basename +'_'+item for item in endings] fis = range(startfi, startfi+NF) for fi, fname in zip(fis, filenames): epsname = fname+'.eps' outpath = os.path.join(figdir, epsname) PU.mysave(outpath, fi=fi) if del_eps: os.remove(outpath)#delete eps but leave pdf
from pylab import * from scipy import * import pylab_util as PU figure(1) xticks(arange(0,1.1,0.2)) grid(1) yticks(arange(-10,10.5,1), \ ['-10','','-8','','-6','','-4','','-2','','0', \ '','2','','4','','6','','8','','10']) ylabel('$\\theta$ (counts)') xlabel('Time (sec)') PU.mysave('blank_encoder_graph.eps',1) show()
myfile = txt_data_processing.Data_File('swept_sine_kp_1_amp_50.txt') #myfile.bode_plot('v','theta',seedfreq=2.45, seedphase=-200.0, label='exp') #myfile.bode_plot('v','a',fignum=2, seedfreq=10.0, seedphase=-150.0, label='exp') myfile.bode_plot(*args1, **kwargs1) myfile.bode_plot(*args2, **kwargs2) kwargs1['clear'] = False kwargs2['clear'] = False myfile2 = txt_data_processing.Data_File('with_accel_01_28_14_test_1.txt') kwargs1['label'] = 'with accel' kwargs2['label'] = 'with accel' args2b = ('v','accel') myfile2.bode_plot(*args1, **kwargs1) myfile2.bode_plot(*args2b, **kwargs2) myfile3 = txt_data_processing.Data_File('without_accel_01_28_14_test_2.txt') kwargs1['label'] = 'no accel' myfile3.bode_plot(*args1, **kwargs1) import pylab_util as PU PU.SetLegend(1, loc=3, axis=0) PU.SetPhaseLim(1,[-260,180]) PU.SetFreqLim(1,[0.1,50]) PU.SetMagLim(1,[-50,30]) PU.mysave('with_and_without_accel_attached.png', fi=1) show()
## # case 14 case = 14 A_list = [0.1, 0.3, 0.5, 0.7, 0.8] B_list = [0.2, 0.4, 0.6, 0.9] A, B = create_case(A_list, B_list, 1, 0) plot_case(A, B, fignum=case, bsty='--', linewidth=2.0) ylim([-0.1, 1.3]) legend(['A', 'B']) curname = outpat % case fno, ext = os.path.splitext(curname) pdfname = fno + '.pdf' pdfpath = os.path.join(folder, pdfname) outpath = os.path.join(folder, curname) save_case(outpath, A, B) pylab_util.mysave(pdfpath) # case 15 ## case = 17 ## B_list = [0.1, 0.3, 0.5, 0.7] ## A_list = [0.4, 0.6, 0.8, 0.9] ## case = 18 ## B_list = [0.1, 0.3, 0.5, 0.8] ## A_list = [0.2, 0.4, 0.6, 0.7] ## A, B = create_case(A_list, B_list, 0, 0) ## A_shift = A + 0.0075 ## plot_case(A_shift, B, fignum=case, bsty='--', linewidth=2.0) ## grid(1) ## ylim([-0.1,1.3])
grid(1) myarray = arange(-1,1,0.2) #mylabels = ['']*5 + ['0'] + ['']*4 mylabels = ['']*5 + [''] + ['']*4 xticks(myarray, mylabels, color=(0,0,0), fontproperties=myprops) yticks(myarray, mylabels, color=(0,0,0), fontproperties=myprops) #myxlabel = '$x_1$' #myylabel = '$x_2$' myxlabel = '' myylabel = '' xlabel(myxlabel) ylabel(myylabel) filename = 'blank_phase_portrait.eps' outdir = '/home/ryan/nonlinear_controls_2011/midterm/' outpath = os.path.join(outdir, filename) pylab_util.mysave(outpath) fno, ext = os.path.splitext(filename) filename1 = fno + '.pdf' filename2 = 'cropped_blank_phase_portrait.pdf' curdir = os.getcwd() os.chdir(outdir) cmd = 'pdfcrop %s %s' % (filename1, filename2) os.system(cmd) os.chdir(curdir) show()
def my_save(note): PU.mysave('theta_bode_%s.png' % note, 1) PU.mysave('accel_bode_%s.png' % note, 2)
th_v_fit, a_v_fit, a_th_fit = mymodel(xf_fit, f2, actvect=actvect) rwkbode.GenBodePlot(1, f2, th_v_fit, clear=False, linetype='r-') rwkbode.GenBodePlot(2, f2, a_v_fit, clear=False, linetype='r-') rwkbode.GenBodePlot(3, f2, a_th_fit, clear=False, linetype='r-') t5 = time.time() pylab_util.SetPhaseLim(1, [-300,0]) pylab_util.SetFreqLim(1, freqlim) pylab_util.SetMagLim(1, [-50, 20]) resave = 0 if resave: pylab_util.mysave('theta_vs_v_bode.png', 1) pylab_util.SetPhaseLim(2, [-450,100]) pylab_util.SetFreqLim(2, freqlim) pylab_util.SetMagLim(2, [-20, 30]) if resave: pylab_util.mysave('accel_vs_v_bode.png', 2) pylab_util.SetPhaseLim(3, [-250,250]) pylab_util.SetFreqLim(3, freqlim) pylab_util.SetMagLim(3, [-20, 50]) t6 = time.time()
def my_save(): PU.mysave("theta_bode.png", 1) PU.mysave("accel_bode.png", 2)
grid(1) myarray = arange(-1, 1, 0.2) #mylabels = ['']*5 + ['0'] + ['']*4 mylabels = [''] * 5 + [''] + [''] * 4 xticks(myarray, mylabels, color=(0, 0, 0), fontproperties=myprops) yticks(myarray, mylabels, color=(0, 0, 0), fontproperties=myprops) #myxlabel = '$x_1$' #myylabel = '$x_2$' myxlabel = '' myylabel = '' xlabel(myxlabel) ylabel(myylabel) filename = 'blank_phase_portrait.eps' outdir = '/home/ryan/nonlinear_controls_2011/midterm/' outpath = os.path.join(outdir, filename) pylab_util.mysave(outpath) fno, ext = os.path.splitext(filename) filename1 = fno + '.pdf' filename2 = 'cropped_blank_phase_portrait.pdf' curdir = os.getcwd() os.chdir(outdir) cmd = 'pdfcrop %s %s' % (filename1, filename2) os.system(cmd) os.chdir(curdir) show()
figure(2) clf() plot(freq, A1, linewidth=2) plot(freq, A2,'--', linewidth=3) xlabel('Freq. (Hz)') ylabel('FFT Mag.') title('real(fft)') legend(['$A_1$','$A_2$'], loc='upper center') figure(3) clf() plot(freq, B1, linewidth=2) plot(freq, B2, '--', linewidth=3) xlabel('Freq. (Hz)') ylabel('FFT Mag.') title('imag(fft)') ylim([-0.1,1]) legend(['$B_1$','$B_2$'], loc='upper center') if os.getlogin() == 'rkrauss': import pylab_util as PU PU.mysave('aliasing_example_cosine.eps',1) PU.mysave('mirror_image_A_coeffs.eps',2) PU.mysave('mirror_image_B_coeffs.eps',3) show()
def mysave(filename, fi): path = os.path.join(fig_dir, filename) PU.mysave(path, fi)
## pdfname = fno + '.pdf' ## pdfpath = os.path.join(folder, pdfname) ## outpath = os.path.join(folder, curname) ## save_case(outpath, A, B) ## pylab_util.mysave(pdfpath) # case 15 ## case = 17 ## B_list = [0.1, 0.3, 0.5, 0.7] ## A_list = [0.4, 0.6, 0.8, 0.9] ## case = 18 ## B_list = [0.1, 0.3, 0.5, 0.8] ## A_list = [0.2, 0.4, 0.6, 0.7] A, B = create_case(A_list, B_list, 0, 1) A_shift = A + 0.0075 plot_case(A_shift, B, fignum=case, bsty='--', linewidth=2.0) grid(1) ylim([-0.1,1.3]) legend(['A','B']) curname = outpat % case fno, ext = os.path.splitext(curname) pdfname = fno + '.pdf' pdfpath = os.path.join(folder, pdfname) outpath = os.path.join(folder, curname) save_case(outpath, A, B) pylab_util.mysave(pdfpath) show()
def save_fig(self, suffix): figpath = self.get_fig_path(suffix) PU.mysave(figpath)
ax2.set_xlim(myfreqlims) ax2.set_ylim([-360,0]) ax2.set_yticks(np.arange(-360,360,90)) bode_utils.mygrid(ax2) ax2.xaxis.set_major_formatter(matplotlib.ticker.NullFormatter()) ax2.yaxis.set_major_formatter(matplotlib.ticker.NullFormatter()) #blank_x_labels(ax2) #blank_y_labels(ax2) #bode_utils.mygrid(ax2) tight_layout() import pylab_util as PU PU.mysave('blank_Bode.eps') #rcParams['figure.subplot.bottom'] = 0.18 ## fig = figure(2, (8,5)) ## fig.clf() ## ax = fig.add_subplot(111) ## ax.set_xscale('log') ## grid(1) ## ax.set_ylabel('dB Mag.\n\n') ## blank_x_labels(ax) ## blank_y_labels(ax) ## ax.set_xlabel('\n\n Freq. (Hz)') #PU.mysave('blank_dB_mag.pdf')
ax.set_yticklabels(empty_labels) blank_x_labels(ax1) blank_y_labels(ax1) ax2 = subplot(212) ax2.set_xscale('log') grid(1) ax2.set_ylabel('Phase (deg.)\n\n') ax2.set_xlabel('\n\n Freq. (Hz)') blank_x_labels(ax2) blank_y_labels(ax2) import pylab_util as PU PU.mysave('blank_Bode.eps') rcParams['figure.subplot.bottom'] = 0.18 fig = figure(2, (8,5)) fig.clf() ax = fig.add_subplot(111) ax.set_xscale('log') grid(1) ax.set_ylabel('dB Mag.\n\n') blank_x_labels(ax) blank_y_labels(ax) ax.set_xlabel('\n\n Freq. (Hz)') PU.mysave('blank_dB_mag.pdf')