otaf.plotting package
Module contents
Codes to plot the various objects, results, shapes, distributions, etc.
- otaf.plotting.arrange_axes_in_grid(axes_list)[source]
Arrange a list of Matplotlib axes into a new, compact 2D grid plot.
Calculates the optimal number of rows and columns to form a near-square layout, creates a new figure, copies lines and labels from the source axes into the subplots, and deletes any unused grid positions.
- Parameters:
axes_list (list) – A list of Matplotlib axis objects whose lines and metadata should be copied.
- Return type:
None
- otaf.plotting.generate_topological_tikz(data, part_positions, feature_positions, color_palette=['#023fa5', '#7d87b9', '#bec1d4', '#d6bcc0', '#bb7784', '#8e063b', '#4a6fe3', '#8595e1', '#b5bbe3', '#e6afb9', '#e07b91', '#d33f6a', '#11c638', '#8dd593', '#c6dec7', '#ead3c6', '#f0b98d', '#ef9708', '#0fcfc0', '#9cded6', '#d5eae7', '#f3e1eb', '#f6c4e1', '#f79cd4'], R_part=15, r_feat=2, scale=0.15)[source]
Generate the raw TikZ LaTeX code to visualize a system topology diagram.
Identifies connected feature components to map colors, initializes the TikZ canvas settings, draws assembly parts as large circles, embeds child features along their outer perimeters, and renders labeled directional loops representing geometric constraints between features.
- Parameters:
data (Dict[str, Any]) – The structured dictionary tracking part properties, feature nodes, and loop pathways.
part_positions (Dict[Any, np.ndarray]) – A dictionary mapping part identifiers to their global (X, Y) layout center coordinates.
feature_positions (Dict[str, Tuple[float, float]]) – A dictionary mapping unique feature codes to their calculated (X, Y) positions.
color_palette (List[str]) – A list of hex color string specs used to format the visual elements dynamically.
R_part (float, default=15) – The base physical radius assigned to the primary part boundary circles.
r_feat (float, default=2) – The base physical radius allocated for individual nested feature nodes.
scale (float, default=0.15) – A scalar factor used to shrink or expand the coordinate dimensions for LaTeX rendering.
- Returns:
The uncompiled, multiline raw TikZ string ready to be placed in a LaTeX document.
- Return type:
str
- Raises:
ImportError – If the networkx library is not installed in the execution environment.
- otaf.plotting.hex_to_rgba(hex_color, alpha=1.0, as_float=False)[source]
Convert a hexadecimal color string to an RGBA tuple.
Strips any leading
'#'character, extracts the red, green, and blue components, and optionally normalizes the RGB values to floats before appending the alpha channel.- Parameters:
hex_color (str) – The hexadecimal color code string (e.g.,
'#ffffff'or'e6e6e6').alpha (float, optional) – The alpha (transparency) value, typically between 0.0 and 1.0. The default is 1.0.
as_float (bool, optional) – If
True, returns RGB values as floats scaled between 0.0 and 1.0. IfFalse, returns them as integers between 0 and 255. The default isFalse.
- Returns:
A four-element tuple containing the red, green, blue, and alpha values in order.
- Return type:
tuple
- otaf.plotting.plot_deviated_surfs(ax, se_pos, se_rot, lambda_, scale_factor, style=None, **style_kwargs)[source]
Overlay deviated profile lines onto a plot to visualize geometric defects.
Iterates through paired positional and rotational variations, scales them by the provided modifiers, and draws calculated deviation lines across a constant vertical span on an existing Matplotlib axis using global styling.
- Parameters:
ax (matplotlib.axes.Axes) – The Matplotlib axis object where the geometric lines will be drawn.
se_pos (Any) – An array or sequence containing positional deviation tracking data.
se_rot (Any) – An array or sequence containing rotational deviation tracking data.
lambda (float) – A weight multiplier balancing positional vs rotational defect components.
scale_factor (float) – A scalar multiplier used to visually exaggerate the defects for readability.
style (dict, optional) – Base style dictionary.
**style_kwargs – Overrides for DEFAULT_FIG_STYLE.
lambda_ (float)
- Returns:
The modified axis object containing the plotted deviation lines.
- Return type:
matplotlib.axes.Axes
- Raises:
AssertionError – If the lengths of the se_pos and se_rot arrays do not match.
- otaf.plotting.plot_deviation_domain(ax, sample, x_label='X', y_label='Y', x_bounds=(-0.15, 0.15), y_bounds=(-1, 1), ratio_bounds=1.5, tick_spacing=(0.25, 0.25), style=None, **style_kwargs)[source]
Plot sample coordinates on a Matplotlib axis with a diamond-shaped tolerance polygon.
Draws a 4-sided boundary polygon using the specified limits, splits data points into groups based on whether they fall inside or outside the polygon boundaries, colors them using the global style configuration, and prints the failure count.
- Parameters:
ax (matplotlib.axes.Axes) – The Matplotlib axis object where the polygon and data points will be rendered.
sample (np.ndarray) – An (N, 2) array containing the coordinate points to plot.
x_label (str, default="X") – The text label for the horizontal X-axis.
y_label (str, default="Y") – The text label for the vertical Y-axis.
x_bounds (Tuple[float, float], default=(-0.15, 0.15)) – The minimum and maximum horizontal intercept coordinates for the polygon.
y_bounds (Tuple[float, float], default=(-1, 1)) – The minimum and maximum vertical intercept coordinates for the polygon.
ratio_bounds (float, default=1.5) – A multiplier used to pad the outer limits of the plot viewport.
tick_spacing (Sequence[float], default=(0.25, 0.25)) – The major locator stepping interval for the X and Y axes ticks respectively.
style (dict, optional) – Base style dictionary.
**style_kwargs – Overrides for DEFAULT_FIG_STYLE.
- Returns:
The modified axis object containing the rendered polygon, scatter plots, and text.
- Return type:
matplotlib.axes.Axes
- otaf.plotting.plot_ensemble_gld_pbox_cdf(gld_obj, param_list, x_values, ax=None, style=None, labels=('Lower bound', 'Upper bound'), fill_color='gray', alpha=0.3, xlabel='Slack', ylabel='Probability of Failure ($P_f$)', title='Probability-Box of the CDF', add_zoom=False, zoom_x_range=(-0.05, 0.05), zoom_y_range=(1e-06, 0.1), inset_log_y=False, **style_kwargs)[source]
Plot a P-Box using custom global styling and saving options.
- Parameters:
...
style (dict, optional) – Base style dictionary.
**style_kwargs – Overrides for DEFAULT_FIG_STYLE (e.g., save=True, save_path=’my_plot.png’)
- otaf.plotting.plot_gld_pbox_cdf(gld_obj, lower_params, upper_params, x_values, xtol=1e-05, labels=None, alpha=0.3, xlabel='X', ylabel='P', title='Probability-Box of the CDF', ax=None, style=None, **style_kwargs)[source]
Plot a Probability-Box (P-Box) by shading the region between two GLD cumulative distributions.
Computes the numerical CDF arrays for both the lower and upper Generalized Lambda Distribution parameters, plots them as bounding lines on a designated Matplotlib axis, and fills the area between them to visualize the uncertainty envelope. Now utilizes global styling configurations.
- Parameters:
gld_obj (Any) – An instance of the GLD class used to calculate numerical CDF values.
lower_params (Any) – An array or sequence of parameters defining the lower-bound distribution.
upper_params (Any) – An array or sequence of parameters defining the upper-bound distribution.
x_values (Any) – An array or sequence of horizontal coordinate points where the curves are evaluated.
xtol (float, default=1e-5) – The numerical convergence tolerance threshold passed to the CDF evaluation function.
labels (Optional[Tuple[str, str]], default=None) – An optional pair of string labels used to identify the bounding curves in the plot legend.
alpha (float, default=0.3) – The opacity level (ranging from 0.0 to 1.0) applied to the filled background region.
xlabel (str, default="X") – The text label for the horizontal X-axis.
ylabel (str, default="P") – The text label for the vertical Y-axis.
title (str, default="Probability-Box of the CDF") – The main header title displayed above the plot grid.
style (dict, optional) – Base style dictionary to pass to the configuration merger.
**style_kwargs – Overrides for DEFAULT_FIG_STYLE (e.g., dpi=150, save=True).
ax (Any | None)
- Returns:
The initialized figure and axes objects.
- Return type:
Tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]
- otaf.plotting.plot_rect_part(ax, scale_factor=100, style=None, **style_kwargs)[source]
Plot the rectangular component of the example mesh or model on an existing axis.
Draws a bounding rectangle using line segments, modifies the visual aspect ratio to be twice as tall and half as wide, and overlays dimensional tracking arrows along with text annotations. Uses global styling for colors and fonts.
- Parameters:
ax (matplotlib.axes.Axes) – The Matplotlib axis object where the geometric lines and annotations are drawn.
scale_factor (float, default=100) – A multiplier applied to scale the horizontal span of the indicator arrows.
style (dict, optional) – Base style dictionary.
**style_kwargs – Overrides for DEFAULT_FIG_STYLE.
- Returns:
The modified axis object containing the rendered layout elements.
- Return type:
matplotlib.axes.Axes
- otaf.plotting.trimesh_scene_as_notebook_scene(scene, background_hex_color='e6e6e6')[source]
Convert a Trimesh scene into an interactive Jupyter notebook widget.
Generates the HTML/JS representation of the scene and modifies the underlying Three.js canvas setup to apply a custom background color.
- Parameters:
scene (trimesh.Scene) – The Trimesh scene object to be displayed.
background_hex_color (str, optional) – The hexadecimal color code (without the
'#'prefix) for the background. Default is'e6e6e6'.
- Returns:
The interactive notebook widget containing the rendered scene.
- Return type:
Any
- Raises:
ImportError – If trimesh viewer dependencies are not installed.