CAMFR icon indicating copy to clipboard operation
CAMFR copied to clipboard

Upgrade to Matplotlib-based plotting

Open demisjohn opened this issue 6 years ago • 6 comments

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 avatar Apr 11 '18 04:04 demisjohn

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 avatar Apr 11 '18 04:04 demisjohn

Notes on CAMFR's field parameters:

  • CAMFR uses 1 as the x axis and 2 as the y axis.

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:

  • E2, H1 = TM
  • E1, H2 = TE

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:

  • E1, H2 = TM
  • E2, H1 = TE

demisjohn avatar Apr 11 '18 04:04 demisjohn

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 avatar Apr 11 '18 04:04 demisjohn

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 avatar Apr 11 '18 04:04 demisjohn

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 avatar Apr 11 '18 04:04 demisjohn

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

demisjohn avatar Apr 11 '18 04:04 demisjohn