Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Matplotlib-based plotting #13

Open
demisjohn opened this issue Apr 11, 2018 · 6 comments
Open

Upgrade to Matplotlib-based plotting #13

demisjohn opened this issue Apr 11, 2018 · 6 comments

Comments

@demisjohn
Copy link
Owner

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: #9

@demisjohn
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link
Owner Author

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

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
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant