anafibre.plotting¶
Functions for visualizing dispersion relations, mode profiles, and wavelength spectra.
plot_dispersion_chart
¶
Plot dispersion residual map and zero contour in (V, b) space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fibre
|
StepIndexFibre
|
Fibre model instance. |
required |
ell
|
int
|
Azimuthal mode index. |
1
|
Vmin
|
float
|
Horizontal-axis limits for normalized frequency. |
(0, 10)
|
Vmax
|
float
|
Horizontal-axis limits for normalized frequency. |
(0, 10)
|
Npoints
|
int
|
Sampling resolution in each axis. |
500
|
bmin
|
float
|
Vertical-axis limits for normalized propagation constant. |
(0, 1)
|
bmax
|
float
|
Vertical-axis limits for normalized propagation constant. |
(0, 1)
|
mode_type
|
(TE, TM, None)
|
TE/TM selector for |
"TE"
|
show_bessel_zeros
|
bool
|
Show Bessel-root ticks on a secondary top axis. |
True
|
colorbar
|
bool
|
Add colorbar for the residual colormap. |
False
|
ax
|
Axes
|
Existing axis to draw on. If omitted, a new figure/axis is created. |
None
|
cbar_label
|
str
|
Colorbar label. |
"$F_\ell(b,V)$"
|
show_xgrid
|
bool
|
Draw major x-grid lines. |
False
|
show_bessel_grid
|
bool
|
Draw vertical guide lines at Bessel roots. |
True
|
bessel_grid_kwargs
|
dict
|
Keyword overrides for Bessel grid line style. |
None
|
ylabel
|
bool
|
Enable axis labels. |
True
|
xlabel
|
bool
|
Enable axis labels. |
True
|
rasterized
|
bool
|
Rasterize the dense pcolormesh for faster vector exports. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axis containing the plot. |
plot_dispersion_vs_wavelength
¶
Plot dispersion residual map and zero contour in (lambda, b) space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fibre
|
StepIndexFibre
|
Fibre model instance. |
required |
ell
|
int
|
Azimuthal mode index. |
1
|
wl_min
|
float
|
Wavelength range in nanometers. |
(400.0, 700.0)
|
wl_max
|
float
|
Wavelength range in nanometers. |
(400.0, 700.0)
|
Npoints
|
int
|
Sampling resolution in each axis. |
500
|
bmin
|
float
|
Vertical-axis limits for normalized propagation constant. |
(0, 1)
|
bmax
|
float
|
Vertical-axis limits for normalized propagation constant. |
(0, 1)
|
mode_type
|
(TE, TM, None)
|
TE/TM selector for |
"TE"
|
show_bessel_zeros
|
bool
|
Draw approximate Bessel-root markers on a top axis. |
True
|
colorbar
|
bool
|
Add colorbar for the residual colormap. |
False
|
ax
|
Axes
|
Existing axis to draw on. If omitted, a new figure/axis is created. |
None
|
cbar_label
|
str
|
Colorbar label. |
"$F_\ell(b,\lambda)$"
|
show_xgrid
|
bool
|
Draw major x-grid lines. |
False
|
show_bessel_grid
|
bool
|
Draw vertical guide lines at approximate Bessel-root locations. |
True
|
bessel_grid_kwargs
|
dict
|
Keyword overrides for Bessel grid line style. |
None
|
ylabel
|
bool
|
Enable axis labels. |
True
|
xlabel
|
bool
|
Enable axis labels. |
True
|
rasterized
|
bool
|
Rasterize the dense pcolormesh for faster vector exports. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axis containing the plot. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If wavelength-to- |
add_visible_spectrum
¶
Adds a visible spectrum color strip below the x-axis of a given plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axis where the strip will be added. |
required |
position
|
list of 4 floats
|
Inset position [x, y, width, height] in axes coordinates. |
[0, 0, 1, 0.01]
|
wls
|
array - like
|
Wavelengths in nanometers to map to RGB. |
linspace(400, 700, 300)
|
xlim
|
tuple
|
If provided, overrides the wavelength range. |
None
|
resolution
|
int
|
Number of color points. |
300
|
xcoords
|
array - like
|
X-axis coordinates where colors should be placed. If provided, the
color is determined from |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Adds an inset spectrum strip to |
plot_xy_vector_field
¶
Plot a transverse vector field with optional longitudinal colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
2D coordinate arrays in meters (or astropy quantities). |
required |
Y
|
array - like
|
2D coordinate arrays in meters (or astropy quantities). |
required |
F
|
array - like
|
Vector field with last axis |
required |
ax
|
Axes
|
Existing axis to draw on. |
None
|
scale
|
(auto, float)
|
Relative multiplier applied to the automatically determined quiver scale from the transverse field amplitude. Use "auto" or None for factor 1.0; provide a number (e.g., 0.7 or 1.5) to shrink/enlarge arrows w.r.t. autoscale. |
"auto"
|
zscale
|
float
|
Symmetric limits for the |
None
|
cmap
|
str
|
Colormap for the |
"RdBu_r"
|
stride
|
int
|
Subsampling factor for quiver arrows. |
4
|
title
|
str
|
Axis title. |
None
|
xlabel
|
str
|
Axis labels. |
None
|
ylabel
|
str
|
Axis labels. |
None
|
colorbar_label
|
str
|
Label for the |
None
|
colorbar
|
bool
|
Whether to draw the |
False
|
density
|
float / str
|
Streamplot styling parameters (used when |
1.0
|
linewidth
|
float / str
|
Streamplot styling parameters (used when |
1.0
|
color
|
float / str
|
Streamplot styling parameters (used when |
1.0
|
type
|
(quiver, streamplot)
|
Vector rendering style. |
"quiver"
|
labels
|
bool
|
Whether to draw axis labels with units. |
False
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axis containing the plot. |
plot_complex_field
¶
Plot a complex scalar field in Cartesian coordinates using HSV mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
array - like
|
Complex scalar field. |
required |
X
|
array - like
|
Cartesian coordinate grids. Used for plot extent and unit-aware labels. |
None
|
Y
|
array - like
|
Cartesian coordinate grids. Used for plot extent and unit-aware labels. |
None
|
ax
|
Axes
|
Existing axis to draw on. |
None
|
variant
|
(dark, light)
|
Encoding style for magnitude in HSV space. |
"dark"
|
gamma
|
float
|
Saturation exponent for |
1.0
|
percentile
|
float
|
Robust percentile used to auto-scale magnitude. |
99.0
|
vmax
|
float
|
Explicit magnitude scaling maximum. |
None
|
show_phase_cbar
|
bool
|
Whether to display phase and magnitude colorbars. |
True
|
show_mag_cbar
|
bool
|
Whether to display phase and magnitude colorbars. |
True
|
phase_ticks
|
tuple
|
Phase colorbar tick locations. |
(-pi, -pi/2, 0, pi/2, pi)
|
phase_cmap
|
matplotlib colormap
|
Cyclic colormap used for phase. |
plt.cm.hsv
|
mag_cmap
|
str
|
Colormap used for magnitude colorbar. |
"gray"
|
coord_unit
|
Unit
|
Target unit for coordinate display when inputs are quantities. |
None
|
title
|
str
|
Plot title and axis labels. |
None
|
xlabel
|
str
|
Plot title and axis labels. |
None
|
ylabel
|
str
|
Plot title and axis labels. |
None
|
phase_label
|
str
|
Colorbar labels. |
'$\\mathrm{Phase}\\;[\\mathrm{rad}]$'
|
mag_label
|
str
|
Colorbar labels. |
'$\\mathrm{Phase}\\;[\\mathrm{rad}]$'
|
cbar_pad_phase
|
float
|
Colorbar spacing. |
0.0
|
cbar_pad_mag
|
float
|
Colorbar spacing. |
0.0
|
use_tex
|
bool
|
Enable full LaTeX text rendering. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_complex_field_polar
¶
Plot a complex scalar field on a polar grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
2D complex array
|
Complex scalar field sampled on (Rho, Phi) grid. |
required |
Rho
|
array - like
|
Polar grid coordinates. Either both (Nr x Nphi) arrays from meshgrid, or 1D arrays with lengths Nr and Nphi respectively. Rho may be an astropy Quantity; Phi may be a Quantity with angle units (converted to rad). |
required |
Phi
|
array - like
|
Polar grid coordinates. Either both (Nr x Nphi) arrays from meshgrid, or 1D arrays with lengths Nr and Nphi respectively. Rho may be an astropy Quantity; Phi may be a Quantity with angle units (converted to rad). |
required |
ax
|
Axes
|
Existing polar axis to draw on. |
None
|
variant
|
(dark, light)
|
Encoding style for magnitude in HSV space. |
"dark"
|
gamma
|
float
|
Saturation exponent for |
1.0
|
percentile
|
float
|
Robust percentile used to auto-scale magnitude. |
99.0
|
vmax
|
float
|
Explicit magnitude scaling maximum. |
None
|
show_phase_cbar
|
bool
|
Whether to display phase and magnitude colorbars. |
True
|
show_mag_cbar
|
bool
|
Whether to display phase and magnitude colorbars. |
True
|
phase_cbar_style
|
(bar, wheel, edge)
|
Visual style for phase legend. |
"bar"
|
coord_unit
|
Unit
|
Target unit for radial coordinate display. |
None
|
core_radius
|
float | Quantity
|
If provided, radial ticks are placed at integer multiples of this value. |
None
|
title
|
str
|
Plot title and radial-axis label. |
None
|
rlabel
|
str
|
Plot title and radial-axis label. |
None
|
show_grid
|
bool
|
Enable polar grid. |
True
|
grid_kwargs
|
dict
|
Style overrides for grid rendering. |
None
|
use_tex
|
bool
|
Enable full LaTeX text rendering. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
animate_fields_xy
¶
Animate instantaneous electric and/or magnetic fields in an XY slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modes
|
GuidedMode | list[GuidedMode]
|
Mode object(s) to superpose. Used in option A. |
None
|
weights
|
complex | list[complex]
|
Relative modal amplitudes/phases aligned with |
None
|
n_radii
|
float
|
Half-width of auto-generated grid in units of core radius. |
2.0
|
Np
|
int
|
Resolution per axis for auto-generated grid. |
200
|
fields
|
list[tuple]
|
Option B: explicit components |
None
|
X
|
array - like
|
Cartesian grids for option B (or override for option A). |
None
|
Y
|
array - like
|
Cartesian grids for option B (or override for option A). |
None
|
z
|
float
|
Axial position for mode evaluation. |
0.0
|
show
|
tuple[str, ...]
|
Any subset of |
("E", "H")
|
scale
|
(auto, float)
|
Arrow scale multiplier. |
"auto"
|
zscale
|
float
|
Fixed symmetric color scale for longitudinal components. |
None
|
cmap
|
str
|
Colormap for longitudinal components. |
"RdBu_r"
|
n_frames
|
int
|
Number of animation frames per period. |
60
|
interval
|
int
|
Delay between frames in milliseconds. |
50
|
figsize
|
tuple
|
Figure size. |
(8, 4.5)
|
robust_p
|
float
|
Percentile used for robust color/normalization scaling. |
99.0
|
quiver_density
|
int
|
Approximate number of arrows per axis. |
20
|
quiver_scale
|
float
|
Base quiver scaling constant. |
25.0
|
eps
|
float
|
Numerical floor used in normalization safeguards. |
1e-30
|
Returns:
| Type | Description |
|---|---|
FuncAnimation
|
Animation object for notebook display or export. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |