XelToFab
API Reference

Visualization

Functions for plotting design fields and extraction results

Import

from xeltofab.field_plots import plot_field, plot_result, plot_comparison

All visualization functions return a matplotlib.figure.Figure object. Call plt.show() to display interactively, or use fig.savefig() to save to a file.


plot_field

def plot_field(state: PipelineState) -> Figure

Plot the raw input design field.

2D fields: Renders a heatmap with the viridis colormap and a color bar labeled "Density". Fields with field_type="density" are displayed with a fixed range of [0, 1]; SDF fields use auto-scaled ranges.

3D fields: Renders three mid-plane slices (XY at mid-Z, XZ at mid-Y, YZ at mid-X) side by side.

import matplotlib.pyplot as plt
from xeltofab import load_field
from xeltofab.field_plots import plot_field

state = load_field("field.npy")
fig = plot_field(state)
plt.show()

plot_result

def plot_result(state: PipelineState) -> Figure

Plot the extraction result after processing.

2D fields: Displays the binary field (or raw field if preprocessing was skipped) as a grayscale background with extracted contours overlaid in red.

3D fields: Renders a 3D triangle surface plot (plot_trisurf) with semi-transparent faces and wireframe edges. Uses best_vertices for the highest-quality geometry available.

import matplotlib.pyplot as plt
from xeltofab import load_field, process
from xeltofab.field_plots import plot_result

state = process(load_field("field.npy"))
fig = plot_result(state)
plt.show()

plot_comparison

def plot_comparison(state: PipelineState) -> Figure

Side-by-side comparison of the input field and the extraction result.

2D fields: Left panel shows the input field heatmap. Right panel shows the binary background with contours overlaid. If volume_fraction is available, it is displayed as the figure title.

3D fields: Left panel shows the mid-Z slice of the input field. Right panel shows a 3D triangle surface plot of the extracted mesh. If volume_fraction is available, it is displayed as the figure title.

import matplotlib.pyplot as plt
from xeltofab import load_field, process
from xeltofab.field_plots import plot_comparison

state = process(load_field("field.npy"))
fig = plot_comparison(state)
fig.savefig("comparison.png", dpi=150)
plt.close(fig)

Outline