[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In you want more control over the field plotting than is provided by the plot
widgets, you can use a set of lower level plotting functions:
#################################################################### # # Illustrates low level plotting. # #################################################################### from camfr import * set_N(40) set_lambda(1.55) # Define materials. GaAs = Material(3.5) air = Material(1.0) # Define geometry. set_lower_PML(-0.1) set_upper_PML(-0.1) wg = Slab(air(2.0) + GaAs(0.2) + air(2.0)) gap = Slab(air(4.2)) s = Stack(wg(0) + gap(1) + wg(0)) inc = zeros(N()) inc[0] = 1 s.set_inc_field(inc) s.calc() # Do some plotting. r_x = arange( 1.5, 2.8, 0.05) r_z = arange(-1.0, 2.0, 0.05) print "Doing some plots. Close window to continue to the next one." wg.plot_n(r_x) wg.mode(0).plot_field(lambda f : f.E2().real, r_x) s.plot_field(lambda f : f.E2().real, r_x, r_z) s.animate_field(lambda f : f.E2(), r_x, r_z) |
This code is pretty self-explanatory. Ranges are used to specify the area to be plotted and the resolutions.
Note the use of Python's lambda functions to indicate which field component to
plot. Lambda functions are little anonymous functions which in this case will
be called on a Field
object. This greatly increases the flexibility of
the plot_field
function: e.g. to plot the absolute value one would
write lambda f : abs(f.E2()**2)
.
In all these plots, you can zoom by dragging a rectangle in the window. Also, left clicking and dragging under the horizontal axis will print the corresponding coordinates. Note that these functions are also very handy in interactive mode, to quickly inspect modes and their field profiles.
Important to note is that animate_field
requires a complex number to
work correctly, so the full complex field component needs to be used rather
than e.g. the real part.
plot_n
, plot_field
and animate_field
can take an additional named argument like filename="out.gif"
which indicates the filename to write the picture to. For pictures, a variety of formats are supported (gif, jpg, png, eps, ...), where the suffix of the filename will determine the format to be used. For animations only uncompressed animated gif is supported.
Note that these plotting functions also work for BlochStack
, BlochMode
and Cavity
.
For additional functionality of these functions, see the reference guide.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by root on August, 27 2008 using texi2html 1.76.