otaf.plotting package
Module contents
- otaf.plotting.arrange_axes_in_grid(axes_list)[source]
Arrange a list of matplotlib axes in a 2D grid as close to a square as possible.
Parameters: axes_list (list): List of matplotlib axes to be arranged in the grid.
- otaf.plotting.calculate_graph_layout(data, R_part=15, r_feat=2, d_feat=1.5, margin=1.5, part_spacing=45, seed=42)[source]
Creates the graph-based representation and computes all spatial coordinates. Includes an iterative untangling step to prevent crossing interaction edges.
- otaf.plotting.calculate_sample_in_deviation_domain(pos_u, theta, lambda_pos, lambda_theta)[source]
Calculates the sample data in the deviation domain.
Parameters: pos_u (array-like): Position data. theta (array-like): Theta data. lambda_pos (float): Lambda position scaling factor. lambda_theta (float): Lambda theta scaling factor.
Returns: np.ndarray: 2D sample data with scaled position and theta.
- otaf.plotting.compare_jacobians(jacobian1, jacobian2, plot_type='side_by_side', class_labels=None)[source]
Compare two Jacobians visually using bar plots with optional class-based background coloring.
Parameters: jacobian1 (np.ndarray): First Jacobian array of shape (32,). jacobian2 (np.ndarray): Second Jacobian array of shape (32,). plot_type (str): Either ‘side_by_side’ or ‘overlay’ to choose plot style. class_labels (np.ndarray): Array of class labels to apply background coloring. Must be same length as Jacobians.
Returns: None: Displays a bar plot for visual comparison.
- Parameters:
jacobian1 (ndarray)
jacobian2 (ndarray)
plot_type (str)
class_labels (ndarray | None)
- otaf.plotting.create_open_cylinder_mesh(radius, height, transform, sections=64)[source]
Creates a trimesh cylinder open on both ends and applies a transformation.
- Parameters:
radius (float)
height (float)
transform (ndarray)
sections (int)
- 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]
Outputs the raw TikZ string. Features are colored by their interaction group, and loops are uniquely colored using the provided palette. Interaction labels are drawn only once per pair to prevent clutter.
- otaf.plotting.hex_to_rgba(hex_color, alpha=1.0, as_float=False)[source]
Converts a hexadecimal color code to RGBA values.
- Parameters:
hex_color (str) – The hexadecimal color code (e.g., ‘#ffffff’).
alpha (float) – The alpha (transparency) value between 0.0 and 1.0 (default is 1.0).
as_float (bool) – If True, returns RGBA values as floats between 0 and 1. If False (default), returns integers.
- Returns:
- A tuple containing the RGBA values as floats (or integers if as_float is False)
and the alpha value as a float (e.g., (1.0, 1.0, 1.0, 1.0)).
- Return type:
tuple
- otaf.plotting.pair_plot(data, labels=None, subset_labels=None, plot_half='both', hide_diag=False, color_by=None)[source]
Creates a pair plot of all combinations of variables in the data array, with additional customization options.
Parameters: - data: 2D numpy array or similar where each column corresponds to a variable. - labels: List of variable names corresponding to the columns of data.
If None, default labels will be used as ‘Var1’, ‘Var2’, etc.
- subset_labels: List of variable names to plot a specific subset of the pair plot.
If None, all variables will be plotted.
- plot_half: Whether to plot the full matrix (‘both’), only the lower triangular (‘lower’),
or only the upper triangular (‘upper’). Defaults to ‘both’.
hide_diag: If True, the diagonal plots will be hidden.
color_by: If provided, the data points will be colored based on the values of this column (array-like).
Returns: - A customized pair plot of all variable combinations.
- otaf.plotting.plot_best_worst_input_data(best_data, worst_data, variable_labels, figsize=(16, 8), labels=True, save_as_png=False, save_path='images', filename='best_worst_input_data.png', dpi=600)[source]
Plot the best and worst 5% input data.
- Parameters:
best_data (list) – List of input data for the best 5%.
worst_data (list) – List of input data for the worst 5%.
variable_labels (list) – List of variable labels.
figsize (tuple, optional) – Size of the figure (width, height) in inches. Defaults to (16, 8).
labels (bool, optional) – Whether to label samples. Defaults to True.
save_as_png (bool, optional) – Whether to save the plot as a PNG. Defaults to False.
save_path (str, optional) – Path to save the plot. Defaults to ‘images’.
filename (str, optional) – Name of the file to save the plot. Defaults to ‘best_worst_input_data.png’.
dpi (int, optional) – Resolution of the saved plot. Defaults to 600 dpi.
- otaf.plotting.plot_best_worst_results(best_results, worst_results, xlabel='Sample Index', ylabel='Failure rate', title='Best and Worst Results Plot', figsize=(10, 6), save_as_png=False, save_path='images', filename='best_worst_results.png', dpi=600)[source]
Plot the best and worst results.
- Parameters:
best_results (array-like) – Array containing the best results.
worst_results (array-like) – Array containing the worst results.
xlabel (str, optional) – Label for the x-axis. Defaults to ‘Sample Index’.
ylabel (str, optional) – Label for the y-axis. Defaults to ‘Failure rate’.
title (str, optional) – Title of the plot. Defaults to ‘Best and Worst Results Plot’.
figsize (tuple, optional) – Size of the figure (width, height) in inches. Defaults to (10, 6).
save_as_png (bool, optional) – Whether to save the plot as a PNG. Defaults to False.
save_path (str, optional) – Path to save the plot. Defaults to ‘images’.
filename (str, optional) – Name of the file to save the plot. Defaults to ‘best_worst_results.png’.
dpi (int, optional) – Resolution of the saved plot. Defaults to 600 dpi.
- otaf.plotting.plot_combined_CDF(distributions, x_min, x_max, color_list=None, legend_list=None)[source]
Plot combined CDFs for multiple distributions.
- otaf.plotting.plot_deviated_surfs(ax, se_pos, se_rot, lambda_, scale_factor)[source]
Adds on the rectangular part a set of deviated lines to visualize the geometrical distribution of the defects and the impact of the allocations. The defects are multiplied by a scaleFactor.
Parameters: ax (matplotlib.axes.Axes): The axis on which to plot. se_pos (array-like): Positional deviations. se_rot (array-like): Rotational deviations. lambda_ (float): Scaling factor for the deviations. scale_factor (float): Factor to scale the deviations.
Returns: matplotlib.axes.Axes: The axis with the plot.
- 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, r=None, tick_spacing=[0.25, 0.25])[source]
Plots a sample in the deviation domain on the provided matplotlib axis.
Parameters: ax (matplotlib.axes.Axes): The axis on which to plot. sample (array-like): 2D sample data with scaled position and theta. x_label (str, optional): Label for the x-axis. Defaults to “X”. y_label (str, optional): Label for the y-axis. Defaults to “Y”. x_bounds (tuple, optional): Bounds for the x-axis. Defaults to (-0.15, 0.15). y_bounds (tuple, optional): Bounds for the y-axis. Defaults to (-1, 1). Returns: matplotlib.axes.Axes: The axis with the plot.
- otaf.plotting.plot_gld_pbox_cdf(gld_obj, lower_params, upper_params, x_values, xtol=1e-05, labels=None, colors=('tab:blue', 'tab:orange'), fill_color='gray', alpha=0.3, xlabel='X', ylabel='P', title='Probability-Box of the CDF')[source]
Plot a Probability-Box (P-Box) using two sets of GLD parameters representing the lower and upper bounds of the CDF.
- Parameters:
gld_obj (object) – An instance of the GLD class from gldpy.
lower_params (array-like) – Parameters for the lower bound GLD.
upper_params (array-like) – Parameters for the upper bound GLD.
x_values (array-like) – X values where the P-box should be computed.
xtol (float, optional) – Tolerance for numerical CDF computation. Default is 1e-5.
labels (tuple of str, optional) – Labels for the lower and upper bound CDFs. Default is None.
colors (tuple of str, optional) – Colors for the lower and upper bound CDFs. Default is (‘tab:blue’, ‘tab:orange’).
fill_color (str, optional) – Color for the filled P-box region. Default is ‘gray’.
alpha (float, optional) – Transparency of the filled region. Default is 0.3.
- otaf.plotting.plot_gld_pbox_cdf2(gld_obj, param_list, x_values, xtol=1e-05, labels=None, colors=('tab:blue', 'tab:orange'), fill_color='gray', alpha=0.3, xlabel='X', ylabel='P', title='Probability-Box of the CDF')[source]
Plot a Probability-Box (P-Box) using two sets of GLD parameters representing the lower and upper bounds of the CDF.
- Parameters:
gld_obj (object) – An instance of the GLD class from gldpy.
lower_params (array-like) – Parameters for the lower bound GLD.
upper_params (array-like) – Parameters for the upper bound GLD.
x_values (array-like) – X values where the P-box should be computed.
xtol (float, optional) – Tolerance for numerical CDF computation. Default is 1e-5.
labels (tuple of str, optional) – Labels for the lower and upper bound CDFs. Default is None.
colors (tuple of str, optional) – Colors for the lower and upper bound CDFs. Default is (‘tab:blue’, ‘tab:orange’).
fill_color (str, optional) – Color for the filled P-box region. Default is ‘gray’.
alpha (float, optional) – Transparency of the filled region. Default is 0.3.
- otaf.plotting.plot_points_3D(points_dict, color='r', marker='o', azim=0)[source]
Create a 3D scatter plot of points.
- Parameters:
points_dict (dict) – A dictionary where keys are labels and values are 3D points (tuples of floats).
color (str, optional) – Color of the markers. Defaults to ‘r’ (red).
marker (str, optional) – Marker style. Defaults to ‘o’ (circle).
azim (float, optional) – Azimuthal viewing angle. Defaults to 0 (front view).
- Return type:
None
- otaf.plotting.plot_rect_part(ax, scale_factor=100)[source]
Plots the rectangular part of the example and changes the aspect ratio, so that it is 2 times higher and 2 times shorter.
Parameters: ax (matplotlib.axes.Axes): The axis on which to plot. scale_factor (float, optional): Scaling factor for the arrows. Defaults to 100.
Returns: matplotlib.axes.Axes: The axis with the plot.
- otaf.plotting.plot_single_transform(transform, figsize=(8, 8), start_color='red', end_color='blue', azim=0)[source]
Plots a single transformation matrix in a 3D space.
Args: - transform (np.ndarray or similar): A 4x4 transformation matrix. - figsize (tuple): Size of the figure. - origin_color (str): Color of the origin point.
- otaf.plotting.plot_transform_sequence(transforms, figsize=(8, 8), origin_color='blue', start_color='red', end_color='blue', azim=0)[source]
Plots a sequence of transformation matrices, showing the transformation of a point across multiple frames.
Args: - transforms (list of np.ndarray or similar): A list of 4x4 transformation matrices. - figsize (tuple): Size of the figure. - origin_color (str): Color of the origin point in each frame.
- otaf.plotting.print_sample_in_deviation_domain(ax, pos_u, theta, lambda_pos, lambda_theta, t_max, theta_max, ratio=1, r=None, xlabel='U', ylabel='Theta', remove_ticks=False, fontsize=15)[source]
Plots a sample in the deviation domain on the provided matplotlib axis with customizable labels and tick options.
Parameters: ax (matplotlib.axes.Axes): The axis on which to plot. pos_u (array-like): Position data. theta (array-like): Theta data. lambda_pos (float): Lambda position scaling factor. lambda_theta (float): Lambda theta scaling factor. t_max (float): Maximum value for t (U domain). theta_max (float): Maximum value for theta (Theta domain). ratio (float, optional): Aspect ratio for the plot. Defaults to 1. r (float, optional): Additional parameter to display. Defaults to None. xlabel (str, optional): Label for the x-axis. Defaults to “U”. ylabel (str, optional): Label for the y-axis. Defaults to “Theta”. remove_ticks (bool, optional): If True, removes axis ticks. Defaults to False.
Returns: matplotlib.axes.Axes: The axis with the plot.
- otaf.plotting.save_plot(fig=None, ax=None, filename='plot', folder='.', file_format='png', dpi=300, **kwargs)[source]
Saves a Matplotlib figure or axis to a specified location with customizable parameters.
- Parameters:
fig (matplotlib.figure.Figure) – The figure to save. Default is None.
ax (matplotlib.axes.Axes) – The axis to save. Default is None.
filename (str) – The name of the file (with or without extension). Default is ‘plot’.
folder (str) – The folder where the file will be saved. Default is current directory ‘.’.
file_format (str) – The format to save the file (e.g., ‘png’, ‘pdf’, ‘svg’). Default is ‘png’.
dpi (int) – The dots per inch (DPI) for the output file. Default is 300.
**kwargs – Other optional keyword arguments for plt.savefig().
- Returns:
The full path of the saved file.
- Return type:
str
- otaf.plotting.set_graph_legends(graph, x_title='', y_title='', title='', legends=None, colors=None)[source]
Sets titles, legends, and colors for the given graph.
Parameters: graph (object): The graph object to be modified. x_title (str, optional): Title for the x-axis. Defaults to an empty string. y_title (str, optional): Title for the y-axis. Defaults to an empty string. title (str, optional): Title for the graph. Defaults to an empty string. legends (list, optional): List of legend labels. Defaults to None. colors (list, optional): List of colors for the graph elements. Defaults to None.
Returns: object: The modified graph object.
- otaf.plotting.spheres_from_point_cloud(pc, radius=1.0, color=[100, 100, 100, 255], global_translation=array([0, 0, 0]))[source]
Create a list of spheres from a point cloud.
- Parameters:
pc (np.ndarray) – The point cloud as an Nx3 numpy array, where N is the number of points.
radius (float, optional) – The radius of the spheres. Defaults to 1.0.
color (List[float], optional) – The color of the spheres as an RGBA list. Defaults to gray.
global_translation (np.ndarray, optional) – A translation vector to apply to all spheres. Defaults to [0, 0, 0].
- Returns:
A list of tr.Trimesh objects representing the spheres.
- Return type:
List[tr.Trimesh]