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 PythonPlotPlanned

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

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