def f(mode, fname): wf = functools.partial(lambda z, x: wavefs[mode - 1](x, z), 0) (fig, ax) = plotting.setup_figure_standard(title=u'Argand diagram for n=%i mode' % mode, xlabel=ur'$\mathrm{Re}\left((\psi\left(x\right)\right)$', ylabel=ur'$\mathrm{Im}\left((\psi\left(x\right)\right)$') plotting.plot_argand(ax, wf, waveguide.slab_gap) plotting.save_figure(fig, fname)
def wrangle(data, target=sentiments): '''Prepare data for classification''' raw_len = len(data.index) # Drop duplicate data data.drop_duplicates('Sentence', inplace=True) # Reverse one-hot encoding to obtain single target vector data['Sentiment'] = data.loc[:, target].idxmax(axis=1) data.drop(target, axis=1, inplace=True) # Define length of sentences by splitting per space data['NumWords'] = data['Sentence'].str.split().str.len() # Remove special characters without meaning # # Pie chart to visualize fraction of useful data print('{} instances of {} ({:.3f}%) remaining.'.format( len(data.index), raw_len, len(data.index) / raw_len * 100.0)) plt.figure() labels = ['Good data', 'Bad data'] sizes = [len(data.index), raw_len - len(data.index)] plt.pie(sizes, labels=labels, autopct='%1.1f%%') plotting.save_figure(plt.gcf(), 'useful_data')
def evaluate_parameter(results, poi, tag, xlabel=None, ylabel=None, categorical=False, log=False, xticklabels=None): # Replace NaN (or None) with 0 to allow for Python-style logical comparison results = results.fillna(0) # Create parameter index (without scores) to filter results with optimum = results.loc[results[selected_score].idxmax()] idx = optimum.index.drop(scores) # Get sample of results where all parameters are identical except for the # parameter of interest sample = results[conjunction([results[n] == optimum[n] for n in idx.drop(poi)])] if categorical: c = sns.catplot(x=poi, y=selected_score, data=sample, kind='bar') plt.ylabel(ylabel if ylabel else selected_score) plt.xlabel(xlabel if xlabel else poi) if xticklabels: vals, labels = plt.xticks() plt.xticks(vals, [xticklabels(l.get_text()) for l in labels], rotation=30) plt.xlabel('') plotting.save_figure(plt.gcf(), tag + '_' + poi) else: sample = sample.sort_values(by=poi) plt.figure() plt.errorbar(x=poi, y=selected_score, data=sample) plt.fill_between(sample[poi], sample[selected_score] - sample[selected_score_std], sample[selected_score] + sample[selected_score_std], alpha=0.2) plt.ylabel(ylabel if ylabel else selected_score) plt.xlabel(xlabel if xlabel else poi) if log: plt.xscale('log') plotting.save_figure(plt.gcf(), tag + '_' + poi)
def f(mode, fname): wavefs_propagated = [] labels = [] for d in dists: wavefs_propagated.append(functools.partial(lambda z,x: wavefs[mode-1](x,z), d)) labels.append('z=%.3fm' % d) (fig, ax) = plotting.setup_figure_standard(title=u'Intensity for n=%i mode' % mode, xlabel=u'Distance accross waveguide (m)', ylabel=u'Wavefunction intensity (arbitrary units)') #fig.hold(True) colours = ['blue', 'orange', 'green', 'purple', 'grey', 'lime', 'cyan', 'yellow', 'black', 'navy', 'teal'] colours.reverse() ax.hold(True) d = [] for (wf, lbl) in zip(wavefs_propagated, labels): d.append(plotting.plot_intensity(ax, wf, waveguide.slab_gap, colour=colours.pop(), label=lbl)) ax.hold(False) if len(dists) != 1: ax.legend(loc='upper left', prop={'size' : 10}) plotting.save_figure(fig, fname) i = 1 for data in d: sio.savemat(fname + str(i) + '.mat',data) i += 1
def f(mode, fname): wf = functools.partial(lambda z,x: wavefs[mode-1](x,z), 0) (fig, ax) = plotting.setup_figure_standard(title=u'Poynting vector for n=%i mode' % mode, xlabel=u'Distance accross waveguide (m)', ylabel=u'Energy flow (right is +)') d = plotting.plot_poynting_vector(ax, wf, waveguide.slab_gap) plotting.save_figure(fig, fname) sio.savemat(fname + '.mat', d)
def f(mode, fname): wavef = lambda x: wavefs[mode-1](x, 0) (fig, reax, imax) = plotting.setup_figure_topbottom(title=u'Wavefunction for n=%i mode' % mode, #fig, reax) = plotting.setup_figure_standard(title=u'Wavefunction for n=%i mode' % mode, xlabel=u'Distance accross waveguide (m)', ylabel=u'Wavefunction (arbitrary units)') d = plotting.plot_wavefunction(reax, imax, wavef, waveguide.slab_gap) plotting.save_figure(fig, fname) sio.savemat(fname + '.mat', d)
def tf_idf(data): param_grid = [ {'vec__stop_words': [None, 'english'], 'vec__ngram_range': [(1, 1), (1, 2)], 'vec__min_df': [3, 4, 5], 'vec__max_df': [0.5, 0.75, 0.9], # 'vec__sublinear_tf': [True, False], 'model': [LinearSVC], 'clf__max_iter': [10000], 'clf__dual': [False, True], 'clf__class_weight': ['balanced'], 'clf__random_state': [0]}, {'vec__stop_words': [None, 'english'], 'vec__ngram_range': [(1, 1), (1, 2)], 'vec__min_df': [1, 2, 3, 4], 'vec__max_df': [0.5, 0.75, 0.9, 0.95], 'vec__sublinear_tf': [True, False], 'model': [MultinomialNB, ComplementNB, BernoulliNB], 'clf__alpha': [0.001, 0.01, 0.1, 1.0]} ] results = mlearning.cross_validate( mlearning.tf_idf, ParameterGrid(param_grid), data['Sentence'], data['Sentiment'] ).sort_values(by='balanced_accuracy_score', ascending=False) print('--- Tf-Idf results ---') print(results .drop(['accuracy_score', 'accuracy_score_std', 'confusion_matrix', 'parameters'], axis=1) .rename({'balanced_accuracy_score': 'bas', 'balanced_accuracy_score_std': 'bas_std'}, axis=1) .head(20)) mlearning.characterize_optimum(results, data, mlearning.tf_idf) # Confusion matrix optimum = results.loc[results['balanced_accuracy_score'].idxmax()] plotting.confusion_heatmap(optimum['confusion_matrix'], sentiments) plotting.save_figure(plt.gcf(), 'confusion_heatmap') plotting.confusion_heatmap(optimum['confusion_matrix'], sentiments, True) plotting.save_figure(plt.gcf(), 'confusion_heatmap_norm') # Hyperparameter dependency evaluate_parameter(results, 'clf__alpha', 'tfidf', ylabel='Balanced accuracy score', xlabel='Alpha', log=True) evaluate_parameter(results, 'vec__max_df', 'tfidf', ylabel='Balanced accuracy score', xlabel='Max doc frequency') evaluate_parameter(results, 'vec__min_df', 'tfidf', ylabel='Balanced accuracy score', xlabel='Min doc frequency') evaluate_parameter(results, 'vec__ngram_range', 'tfidf', ylabel='Balanced accuracy score', xlabel='n-gram range', categorical=True) evaluate_parameter( results, 'model', 'tfidf', ylabel='Balanced accuracy score', categorical=True, xticklabels=lambda x: str(x).split("'")[1].split('.')[-1])
def characterize(data): '''Characterize the data visually''' # Bias in terms of sentiment plt.figure() plotting.save_figure(sns.countplot(x='Sentiment', data=data), 'sentiment_balance') # Overview of length of sentences plt.figure() plotting.save_figure(sns.distplot(data['NumWords']), 'num_words') # Overview of length of sentences per sentiment plt.figure() colors = plotting.palette() fig, axs = plt.subplots(1, 3, figsize=(15, 6), sharey=True) for sentiment, ax in zip(sentiments, axs): color = next(colors) p = sns.distplot(data.loc[data['Sentiment'] == sentiment, 'NumWords'], bins=8, ax=ax, color=color, hist=True, kde=False, norm_hist=True, fit=stats.lognorm, fit_kws={'color': color}) p.set_title(sentiment) # plt.legend() plotting.save_figure(plt.gcf(), 'num_words_sentiments') # Overview of length of sentences per sentiment plt.figure() colors = plotting.palette() for sentiment, ax in zip(sentiments, axs): sns.distplot(data.loc[data['Sentiment'] == sentiment, 'NumWords'], bins=8, label=sentiment, hist=False, kde=False, norm_hist=True, fit=stats.lognorm, fit_kws={'color': next(colors)}) plt.legend() plotting.save_figure(plt.gcf(), 'num_words_fits') # Visualize splitting of data plt.figure() fold = StratifiedKFold(n_splits=5) plotting.cross_validation_indices( fold, data['Sentence'], data['Sentiment'].map( {'Negative': 0, 'Neutral': 1, 'Positive': 2}).sort_values(), ax, 5) plotting.save_figure(plt.gcf(), 'stratified_cross_fold')
def sp_plot_wavefunction(waveguide, wavelength, angle, out_file, verbose=False): """ This method produces a wavefunction hitting the waveguide at angle, and splits it into the guided modes of the waveguide. The resultant wavefunction is plotted @param waveguide: The waveguide being illuminated @type waveguide: PlanarWaveguide @param wavelength: The wavelength of light illuminating the waveguide @type wavelength: float @param angle: The angle of the plane waves striking the waveguide, in radian @type angle: float @param out_file: The filename to write output to @type out_file: str @param verbose: Whether or not to give verbose output @type verbose: bool @return: None """ solver = modesolvers.ExpLossySolver(waveguide, wavelength) kxs = solver.solve_transcendental(verbose=verbose) wavefs = solver.get_wavefunctions(kxs, verbose=verbose) k = 2*np.pi/wavelength inkx = k*np.sin(angle) inwave = lambda x: np.exp(1j*inkx*x) splitter = splitters.ModeSplitter(inwave, wavefs) cm = splitter.get_coupling_constants() wffull = splitter.get_wavefunction(cm) wf = functools.partial(lambda z,x: wffull(x,z), 0.005) if verbose: print 'Coupling coefficients: ' for (i,c) in enumerate(cm): print '\t %i: Magnitude: %f, Phase: %f, Square: %f' % (i+1, np.abs(c), np.angle(c), np.abs(c)**2) (fig, reax, imax) = plotting.setup_figure_topbottom(title=ur'Wavefunction for incidence angle $\theta=%f$ rad' % angle, xlabel=u'Distance accross waveguide (m)', ylabel=u'Wavefunction (arbitrary units)') #plotting.plot_intensity(reax, wf, waveguide.slab_gap) #phasef = lambda x: np.angle(wf(x)) plotting.plot_wavefunction(reax, imax, wf, waveguide.slab_gap) plotting.save_figure(fig, unicode(out_file))
def f(mode, fname): kx = kxs[mode-1] inwave = lambda x: np.exp(1j*kx.real*x) splitter = splitters.ModeSplitter(inwave, wavefs) cm = splitter.get_coupling_constants() wffull = splitter.get_wavefunction(cm) wf = lambda x: wffull(x, 0.005) #(fig, reax, imax) = plotting.setup_figure_topbottom( # title=ur'Wavefunction for incidence angle on n=%i mode' % mode, # xlabel=u'Distance accross waveguide (m)', # ylabel=u'Wavefunction (arbitrary units)') (fig, ax) = plotting.setup_figure_standard( title=ur'Wavefunction for incidence angle on n=%i mode' % mode, xlabel=u'Distance accross waveguide (m)', ylabel=u'Wavefunction (arbitrary units)') #plotting.plot_wavefunction(reax, imax, wf, waveguide.slab_gap) plotting.plot_intensity(ax, wf, waveguide.slab_gap) plotting.save_figure(fig, fname) coefftable[mode-1, :] = np.abs(cm)**2
def sp_plot_coupled_map(waveguide, wavelength, angle, zlimits, out_file, verbose=False): """ This method produces a plot of the intensity map in the waveguide when it is illuminated by a plane wave of arbitrary angle @param waveguide: The waveguide being illuminated @type waveguide: PlanarWaveguide @param wavelength: The wavelength of light illuminating the waveguide @type wavelength: float @param angle: The angle of the plane waves striking the waveguide, in radian @type angle: float @param zlimits: The z-axis limits within which to plot the wavefunction @type zlimits: tuple @param out_file: The filename to write output to @type out_file: str @param verbose: Whether or not to give verbose output @type verbose: bool @return: None """ #do the decomposition solver = modesolvers.ExpLossySolver(waveguide, wavelength) kxs = solver.solve_transcendental(verbose=verbose) wavefs = solver.get_wavefunctions(kxs, verbose=verbose) k = 2 * np.pi / wavelength inkx = k * np.sin(angle) inwave = lambda x: np.exp(1j * inkx * x) splitter = splitters.ModeSplitter(inwave, wavefs) cm = splitter.get_coupling_constants() wffull = splitter.get_wavefunction(cm) (fig, ax) = plotting.setup_figure_standard( title=ur'Intensity for incidence angle %f rads' % angle, xlabel=u'Longitudinal distance accross waveguide (m)', ylabel=u'Transverse distance accross waveguide (m)') (X,Y,Z) = plotting.plot_intensity_map(ax, wffull, waveguide.slab_gap, zlimits) plotting.save_figure(fig, unicode(out_file)) sio.savemat(out_file + '.mat', {'inten' : Z, 'X' : X, 'Y' : Y})
def sp_plot_total_coupling(waveguide, wavelength, out_file, verbose=False): solver = modesolvers.ExpLossySolver(waveguide, wavelength) kxs = solver.solve_transcendental(verbose=verbose) wavefs = solver.get_wavefunctions(kxs, verbose=verbose) tirang = waveguide.critical_angle(wavelength) angs = np.linspace(0, tirang+0.1*tirang, num=100) intensity = np.zeros(100) k = 2*np.pi/wavelength pb = progressbar.ProgressBar(widgets=['Calculating Integrals: ', progressbar.Percentage(), progressbar.Bar()], maxval=len(angs)) if verbose: pb.start() for (n,a) in enumerate(angs): kx = np.sin(a)*k inwave = lambda x: np.exp(1j*kx*x) splitter = splitters.ModeSplitter(inwave, wavefs) cm = splitter.get_coupling_constants() wffull = splitter.get_wavefunction(cm) wf = lambda x: wffull(x, 0) integrand = lambda x: np.abs(wf(x))**2 area = integrate.quad(integrand, -1e-6, 1e-6, limit=3000)[0] intensity[n] = area if verbose: pb.update(n) (fig, ax) = plotting.setup_figure_standard(title=u'Coupling efficiency of waveguide', xlabel=u'Angle of radiation incidence (rads)', ylabel=u'Intensity Coupled') ax.plot(angs, intensity) plotting.save_figure(fig, out_file) sio.savemat(out_file + '.mat', {'angs' : angs, 'Intensity' : intensity})
linewidth=1.5, zorder=5) i += 1 nodes = [1, 8, 27, 64, 125, 216] strnodes = ['$' + str(x) + '^3$' for x in [1, 2, 3, 4, 5, 7, 9]] ax.set_xscale("log", nonposx='clip') #ax.set_yscale("log", nonposy='clip') #ax.set_yticks(nodes) #ax.set_yticklabels(np.array(nodes, dtype=int)) ax.set_xticks(nodes) ax.set_xticklabels(strnodes) ax.plot(nodes, np.ones(len(nodes)), "k--", label="ideal") ax.set_xlabel("Nodes") ax.set_ylabel("Efficiency $E = \dfrac{t_1 N}{t_N}$") plt.legend() #frameon=False) myplt.set_font_sizes(ax) myplt.make_grid(ax, True) if blood: myplt.save_figure(fig, 3, 'strong_scale_blood.pdf') else: myplt.save_figure(fig, 3, 'strong_scale_poiseuille.pdf') plt.show()
def ic_exit_surface(waveguide, sourcecls, angle, nwaves, out_file, verbose=False): """ This method implements incoherent --exitsurface behaviour It plots the intensity profile at the exit surface of the waveguide when it is illuminated with incoherent radiation from source at an angle of angle @param waveguide: The waveguide being illuminated @type waveguide: PlanarWaveguide @param source: The characteristics of the source that is generating the radiation hitting this waveguide @type source: type @param angle: The angle the waveguide is tilted at with respect to the source @type angle: float @param nwaves: The number of waves to contribute to the plot of the exit surface @type nwaves: int @param out_file: The file to write the resultant plot to @type out_file: str @param verbose: Whether or not to give verbose output @type verbose: bool @return: None """ source = sourcecls(angle) intensity = np.zeros((250,500)) (X, Y) = np.meshgrid(np.linspace(0, waveguide.length, 500), np.linspace(-waveguide.slab_gap, waveguide.slab_gap, 250)) #let's see if our source is monochromatic prevval = source.get_wave()[1] ismonochrome = True for i in range(10): newval = source.get_wave()[1] ismonochrome = ismonochrome and prevval == newval prevval = newval if ismonochrome: #get this done once solver = modesolvers.ExpLossySolver(waveguide, prevval) kx = solver.solve_transcendental(verbose=False) #this'll get real noisy otherwise modewaves = solver.get_wavefunctions(kx, verbose=False) pb = progressbar.ProgressBar(widgets=['Performing Incoherent Sum: ', progressbar.Percentage(), progressbar.Bar()], maxval=nwaves) if verbose: pb.start() #We need to iterate over many waves, summing their intensity for i in xrange(nwaves): #get a wave (wave, wl) = source.get_wave() inwave = lambda x: wave(x, 0) #only intersted in incidence surface #solve modes for this wl if not ismonochrome: solver = modesolvers.ExpLossySolver(waveguide, wl) kx = solver.solve_transcendental(verbose=False) #this'll get real noisy otherwise modewaves = solver.get_wavefunctions(kx, verbose=False) #split wave into modes splitter = splitters.ModeSplitter(inwave, modewaves) cm = splitter.get_coupling_constants() wffull = splitter.get_wavefunction(cm) #get wavefunction at exit surface exitf = lambda x,y: np.abs(wffull(y, x))**2 #incoherently add exitf to the picture so far exitvf = np.vectorize(exitf) intensity = intensity + exitvf(X,Y) if verbose: pb.update(i+1) #now plot it (fig, ax) = plotting.setup_figure_standard( title=ur'Exit surface intensity', xlabel=u'Longitudinal distance across waveguide (m)', ylabel=u'Transverse distance across waveguide (m)') #ax.plot(x, intensity, color='blue', linestyle='-', marker=None, antialiased=True) #ax.set_xlim((-waveguide.slab_gap, waveguide.slab_gap)) #ax.set_ylim((np.min(intensity) - 0.1 * np.abs(np.min(intensity)), # np.max(intensity) + 0.1 * np.abs(np.max(intensity)))) #plotting.shade_waveguide(ax, waveguide.slab_gap) #Consider only the rightmost 4/5ths when setting the intensity #lowest = np.min(intensity[:, 360:]) #highest = np.max(intensity[:, 360:]) pcm = ax.pcolor(X, Y, intensity, cmap=matplotlib.cm.jet) ax.get_figure().colorbar(pcm, ax=ax, use_gridspec=True) ax.set_xlim((0, waveguide.length)) ax.set_ylim((-waveguide.slab_gap, waveguide.slab_gap)) #bang down a slightly different guideline for the waveguide limits topr = Rectangle((0, waveguide.slab_gap / 2), waveguide.length, waveguide.slab_gap / 2, hatch='\\', fill=False) bottomr = Rectangle((0, -waveguide.slab_gap), waveguide.length, waveguide.slab_gap / 2, hatch='/', fill=False) ax.add_patch(topr) ax.add_patch(bottomr) plotting.save_figure(fig, unicode(out_file)) #save the data too sio.savemat(out_file+'.mat', {'intensity':intensity, 'X':X, 'Y':Y})
plt.plot(nodes, dump, '--', label='Data dump', linewidth=1.5, zorder=3, color='C1') plt.plot(nodes, total, '-', label='Total', linewidth=2.5, zorder=2, color='C2') nodes = [x**3 for x in [1, 2, 3, 4, 5, 6]] strnodes = ['$' + str(x) + '^3$' for x in [1, 2, 3, 4, 5, 6]] ax.set_xscale("log", nonposx='clip') #ax.set_yscale() #ax.set_yscale("log", nonposy='clip') #ax.set_yticks(nodes) #ax.set_yticklabels(np.array(nodes, dtype=int)) ax.set_xticks(nodes) ax.set_xticklabels(strnodes) ax.set_xlabel("Nodes") ax.set_ylabel("Time per step, \si{\milli\second}") plt.legend() #frameon=False) myplt.set_font_sizes(ax) myplt.make_grid(ax) myplt.save_figure(fig, 3, 'datadump.pdf') #plt.show()
zorder=5) i += 1 nodes = [x**3 for x in [1, 2, 3, 4, 5, 7, 9]] strnodes = ['$' + str(x) + '^3$' for x in [1, 2, 3, 4, 5, 7, 9]] ax.set_xscale("log", nonposx='clip') #ax.set_yscale() #ax.set_yscale("log", nonposy='clip') #ax.set_yticks(nodes) #ax.set_yticklabels(np.array(nodes, dtype=int)) ax.set_xticks(nodes) ax.set_xticklabels(strnodes) ax.plot(nodes, np.ones(len(nodes)), "k--", label="ideal") ax.set_xlabel("Nodes") ax.set_ylabel("Efficiency $E = \dfrac{t_1}{t_N}$") plt.legend() #frameon=False) myplt.set_font_sizes(ax) myplt.make_grid(ax, True) if blood: myplt.save_figure(fig, 3, 'weak_scale_blood.pdf') else: myplt.save_figure(fig, 3, 'weak_scale_poiseuille.pdf') plt.show()
def ic_far_field(waveguide, sourcecls, angle, nwaves, out_file, verbose=False): """Pretty shameless copy-paste of the exit_surface method follows""" source = sourcecls(angle) intensity = np.zeros(500) xv = np.linspace(-waveguide.slab_gap, waveguide.slab_gap, 500) #let's see if our source is monochromatic prevval = source.get_wave()[1] ismonochrome = True for i in range(10): newval = source.get_wave()[1] ismonochrome = ismonochrome and prevval == newval prevval = newval if ismonochrome: #get this done once solver = modesolvers.ExpLossySolver(waveguide, prevval) kx = solver.solve_transcendental(verbose=False) #this'll get real noisy otherwise modewaves = solver.get_wavefunctions(kx, verbose=False) pb = progressbar.ProgressBar(widgets=['Performing Incoherent Sum: ', progressbar.Percentage(), progressbar.Bar()], maxval=nwaves) if verbose: pb.start() #We need to iterate over many waves, summing their intensity for i in xrange(nwaves): #get a wave (wave, wl) = source.get_wave() inwave = lambda x: wave(x, 0) #only intersted in incidence surface #solve modes for this wl if not ismonochrome: solver = modesolvers.ExpLossySolver(waveguide, wl) kx = solver.solve_transcendental(verbose=False) #this'll get real noisy otherwise modewaves = solver.get_wavefunctions(kx, verbose=False) #split wave into modes splitter = splitters.ModeSplitter(inwave, modewaves) cm = splitter.get_coupling_constants() wffull = splitter.get_wavefunction(cm) #get wavefunction at exit surface exitf = lambda x: wffull(x, waveguide.length) #incoherently add exitf to the picture so far exitvf = np.vectorize(exitf) exitdata = exitvf(xv) farfield = fft.fft(exitdata) intensity = intensity + np.abs(fft.fftshift(farfield))**2 if verbose: pb.update(i + 1) #now plot it (fig, ax) = plotting.setup_figure_standard( title=ur'Propagated Intensity', xlabel=u'Intensity at screen (arbitrary units)', ylabel=u'Relative transverse distance on screen (m)') ax.plot(xv, intensity, color='blue', linestyle='-', marker=None, antialiased=True) ax.set_xlim((-waveguide.slab_gap, waveguide.slab_gap)) ax.set_ylim((np.min(intensity) - 0.1 * np.abs(np.min(intensity)), np.max(intensity) + 0.1 * np.abs(np.max(intensity)))) plotting.shade_waveguide(ax, waveguide.slab_gap) #Consider only the rightmost 4/5ths when setting the intensity #lowest = np.min(intensity[:, 360:]) #highest = np.max(intensity[:, 360:]) #pcm = ax.pcolor(X, Y, intensity, cmap=matplotlib.cm.jet) #ax.get_figure().colorbar(pcm, ax=ax, use_gridspec=True) #ax.set_xlim((0, waveguide.length)) #ax.set_ylim((-waveguide.slab_gap, waveguide.slab_gap)) #bang down a slightly different guideline for the waveguide limits #topr = Rectangle((0, waveguide.slab_gap / 2), waveguide.length, waveguide.slab_gap / 2, hatch='\\', fill=False) #bottomr = Rectangle((0, -waveguide.slab_gap), waveguide.length, waveguide.slab_gap / 2, hatch='/', fill=False) #ax.add_patch(topr) #ax.add_patch(bottomr) plotting.save_figure(fig, unicode(out_file)) #save the data too sio.savemat(out_file + '.mat', {'intensity': intensity, 'xv' : xv})