Plotting

PhoXonic.jl provides two plotting paths via package extensions:

ExtensionTriggerFunctionality
RecipesBaseExtusing RecipesBase (or any backend)plot(bs) recipe for BandStructure
PlotsExtusing Plotsplot_bands, plot_bands! (full-featured)
PythonPlotExtusing PythonPlotsavefig_publication (publication-quality PDF/PNG)

RecipesBase Recipe

The lightweight recipe is activated when any RecipesBase-compatible backend is loaded.

using PhoXonic, Plots   # or CairoMakie, etc.

solver = Solver(TEWave(), geo, (64, 64))
bs = compute_bands(solver, kpath)

plot(bs)
AttributeDefault
xlabel"Wave vector"
ylabel"Frequency"
legendfalse
gridtrue
linewidth2

Override any attribute with standard keyword arguments:

plot(bs, ylabel="ω a / 2πc", title="TE Bands", linewidth=1)

Plots.jl Functions

These functions require using Plots and provide additional features such as high-symmetry point tick labels, scatter mode for 3D, and band gap highlighting.

plot_bands

using PhoXonic, Plots

bs = compute_bands(solver, kpath)
p = plot_bands(bs; title="TE Bands", show_gaps=true)
savefig(p, "bands.png")

Scatter mode (recommended for 3D to avoid line artifacts at Γ point):

p = plot_bands(bs; scatter=true, markersize=2)

plot_bands!

Add band structure to an existing plot:

p = plot_bands(bs_te; color=:blue, title="TE + TM")
plot_bands!(p, bs_tm; color=:red)

Options

OptionTypeDefaultDescription
colorSymbol:blueLine/marker color
linewidthInt2Line width
scatterBoolfalseUse scatter instead of lines
markersizeInt3Marker size (scatter mode)
titleString"Band Structure"Plot title
ylabelString"Frequency"Y-axis label
show_gapsBoolfalseHighlight band gaps
gap_colorSymbol:yellowGap highlight color
gap_alphaFloat640.2Gap highlight transparency
normalizeFloat641.0Frequency normalization factor

band_plot_data

Extract raw plot data from a BandStructure (backend-independent):

data = band_plot_data(bs; normalize=1.0)
# data.distances, data.frequencies, data.label_positions, data.label_names

PythonPlot — Publication-Quality Figures

Activated when using PythonPlot is loaded. Provides savefig_publication for matplotlib-backed PDF/PNG output with precise axis-size control suitable for journal submissions.

savefig_publication

Single BandStructure:

using PhoXonic, PythonPlot

bs = compute_bands(solver, kpath)
savefig_publication(bs, "bands.pdf"; axis_width_cm=8.0, axis_height_cm=6.0,
                    title="TE Bands")

Multiple BandStructure as subplots:

savefig_publication([bs_te, bs_tm], "te_tm.pdf"; layout=(1, 2))

Multiple BandStructure as overlay (single axis):

savefig_publication([bs_te, bs_tm], "te_tm_overlay.pdf"; overlay=true,
                    title="TE vs TM")

Options

OptionTypeDefaultDescription
axis_width_cmReal8.0Axis width in centimeters
axis_height_cmReal6.0Axis height in centimeters
ylimsTuple or nothingnothingY-axis range (auto if nothing)
titleString""Plot title (suppressed if empty)
show_gapsBoolfalseHighlight band gaps with axhspan
normalizeReal1.0Frequency normalization factor
layoutTuple(1, n)Subplot grid (nrows, ncols)
overlayBoolfalsePlot all on a single axis

The output format is inferred from the file extension (.pdf, .png, .svg, etc., as supported by matplotlib).


API Reference

PhoXonic.plot_bandsFunction
plot_bands(bs::BandStructure; kwargs...)

Plot a band structure diagram.

Arguments

  • bs: BandStructure object from compute_bands()

Keyword Arguments

  • color: Line/marker color (default: :blue)
  • linewidth: Line width (default: 2)
  • scatter: Use scatter plot instead of lines (default: false). Recommended for 3D band structures where Γ point anomalies may occur.
  • markersize: Marker size for scatter plot (default: 3)
  • markershape: Marker shape for scatter plot (default: :circle)
  • title: Plot title (default: "Band Structure")
  • ylabel: Y-axis label (default: "Frequency")
  • show_gaps: Highlight band gaps (default: false)
  • gap_color: Color for gap highlighting (default: :yellow)
  • gap_alpha: Transparency for gap highlighting (default: 0.2)
  • normalize: Normalization factor for frequency (default: 1.0)

Returns

A Plots.jl plot object.

Example

using PhoXonic, Plots
solver = Solver(TEWave(), geo, (64, 64))
bands = compute_bands(solver, kpath)
p = plot_bands(bands; title="TE Bands", show_gaps=true)
savefig(p, "bands.png")

# For 3D, use scatter to avoid line artifacts at Γ point
p = plot_bands(bands; scatter=true, markersize=2)
source
PhoXonic.band_plot_dataFunction
band_plot_data(bs::BandStructure; normalize=1.0)

Extract data for plotting a band structure.

Returns a NamedTuple with:

  • distances: K-path distances
  • frequencies: Normalized frequency matrix
  • label_positions: Positions of high-symmetry points
  • label_names: Names of high-symmetry points
source
PhoXonic.savefig_publicationFunction
savefig_publication(bs::BandStructure, path; kwargs...)
savefig_publication(bss::AbstractVector{<:BandStructure}, path; kwargs...)

Save a publication-quality band structure figure via the PythonPlot extension. Requires using PythonPlot to activate PhoXonicPythonPlotExt.

The output format is inferred from the file extension (.pdf, .png, .svg, ...).

Keyword arguments

  • axis_width_cm = 8.0, axis_height_cm = 6.0 — Axis size in centimeters.
  • ylims = nothing — Y-axis range (auto if nothing).
  • title = "" — Plot title (suppressed if empty).
  • show_gaps = false — Shade band gaps with axhspan.
  • normalize = 1.0 — Frequency normalization factor (forwarded to band_plot_data).
  • layout = (1, length(bss)) — Subplot grid for the vector overload.
  • overlay = false — Plot all bss on a single axis (vector overload).

See also: plot_bands for interactive plotting with Plots.jl.

source