demisjohn / CAMFR

Python-based electromagnetic simulator and mode solver for nanophotonics applications, using the Eigenmode Expansion (EME) method.
GNU General Public License v2.0
65 stars 30 forks source link

Upgrade to Matplotlib-based plotting #13

Open demisjohn opened 6 years ago

demisjohn commented 6 years ago

From @demisjohn on March 7, 2018 14:6

Mode solvers should use MatPlotLib to plot.

Should generate nice colored plots, like this:

modeprofile - 800px

Copied from original issue: demisjohn/CAMFR#9

demisjohn commented 6 years ago

Maybe remove the entire PIL-based (now Pillow) plotting libraries, which seem to be generating their own plotting interfaces etc. Instead just use MatPlotLib which is installed with every Scientific Python package.

demisjohn commented 6 years ago

Notes on CAMFR's field parameters:

In a Section (2D X/Y cross-section), x is the horizontal axis, and y is the vertical axis with z again the direction of propagation.

For a Section:

In a Slab (1D cross-section), the dielectric layers are stacked along the x direction, and z is the direction of propagation. The slab is extended infinitely along y (or really it's only a 2D space, y doesn't exist).

So for a Slab:

demisjohn commented 6 years ago

Added MPL-based mode plotting for Section objects, in eed4cfc8da550cee69b3f9242aa0a28903fd4a22.

SectionObj.plot() now generates a plot like this:

screen shot 2018-03-12 at 12 39 39 am

One can optionally include more modes or fields like so (dx/dy step increased for low res. image/faster plotting):

>>> fig = s.plot(mode=[0,1], field=['Ex', 'Ey'], dx=0.3, dy=0.3)

screen shot 2018-03-12 at 12 41 43 am

Allowing one to save the figure or manipulate axes etc.

fig.savefig('FigureImage.png')

Still need to add to Slab or other objects. What other objects need this?

demisjohn commented 6 years ago

I believe the new matplotlib-based Section.plot() may have inadvertently stomped on top of the existing plot() method which generated it's own Pillow-based 1-D field plotting windows.

I think the 2D MPL one is probably a lot better while providing the same info as the old Pillow one, but should check this to make sure.

demisjohn commented 6 years ago

Should re-use camfr_PIL.py code, which already has functions for returning field values etc.

Also, make function to parse string args for component = "Ey", "Ex" etc., and return the corresponding CAMFR component object "E2", "E1" etc.

demisjohn commented 6 years ago

bottom of CAMFR_PIL.py sets up the PIL-based plotting functions:

############################
# Inject plot functions into C++ classes.
#
################################
import slab_plot, stack_plot

Slab.plot       = lambda self : slab_plot.SlabPlot(self)
Stack.plot      = lambda self : stack_plot.StackPlot(self)
BlochStack.plot = lambda self : stack_plot.StackPlot(self)
Cavity.plot     = lambda self : stack_plot.StackPlot(self)

Slab.plot_n = plot_n
Circ.plot_n = plot_n

Mode.plot_field = plot_field

Stack.plot_n        = plot_n
Stack.plot_field    = plot_field
Stack.animate_field = animate_field

BlochStack.plot_n = plot_n

BlochMode.plot_field    = plot_field
BlochMode.animate_field = animate_field

Cavity.plot_n        = plot_n
Cavity.plot_field    = plot_field
Cavity.animate_field = animate_field