Plotting
PhoXonic.jl provides two plotting paths via package extensions:
| Extension | Trigger | Functionality |
|---|---|---|
| RecipesBaseExt | using RecipesBase (or any backend) | plot(bs) recipe for BandStructure |
| PlotsExt | using Plots | plot_bands, plot_bands! (full-featured) |
| PythonPlotExt | using PythonPlot | Planned |
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)| Attribute | Default |
|---|---|
| xlabel | "Wave vector" |
| ylabel | "Frequency" |
| legend | false |
| grid | true |
| linewidth | 2 |
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
| Option | Type | Default | Description |
|---|---|---|---|
color | Symbol | :blue | Line/marker color |
linewidth | Int | 2 | Line width |
scatter | Bool | false | Use scatter instead of lines |
markersize | Int | 3 | Marker size (scatter mode) |
title | String | "Band Structure" | Plot title |
ylabel | String | "Frequency" | Y-axis label |
show_gaps | Bool | false | Highlight band gaps |
gap_color | Symbol | :yellow | Gap highlight color |
gap_alpha | Float64 | 0.2 | Gap highlight transparency |
normalize | Float64 | 1.0 | Frequency 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_namesAPI Reference
PhoXonic.plot_bands — Function
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)PhoXonic.plot_bands! — Function
plot_bands!(p, bs::BandStructure; kwargs...)Add band structure to an existing plot.
PhoXonic.band_plot_data — Function
band_plot_data(bs::BandStructure; normalize=1.0)Extract data for plotting a band structure.
Returns a NamedTuple with:
distances: K-path distancesfrequencies: Normalized frequency matrixlabel_positions: Positions of high-symmetry pointslabel_names: Names of high-symmetry points