From 93b3e1f4dfcc960e2a9778b8e319a8a130eb94ea Mon Sep 17 00:00:00 2001 From: vhirtham Date: Sun, 21 Mar 2021 19:06:48 +0100 Subject: [PATCH] Add scaling factor (#293) * Add scaling factor * Update changelog * Fix deepsource issue * fix pydocstyle issue * update CHANGELOG.md Co-authored-by: Cagtay Fabry <43667554+CagtayFabry@users.noreply.github.com> --- CHANGELOG.md | 4 +++- weldx/transformations/cs_manager.py | 5 ++++ weldx/transformations/local_cs.py | 6 ++++- weldx/visualization/matplotlib_impl.py | 33 ++++++++++++++++++++++---- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 346a9b0f7..6698a6991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes -## 0.3.1 (unreleased) +## 0.3.1 (21.03.2021) ### added @@ -20,6 +20,8 @@ [[#291]](https://github.com/BAMWelDX/weldx/pull/291) - use `pint` compatible array syntax in `IsoBaseGroove.to_profile()` methods [[#189]](https://github.com/BAMWelDX/weldx/pull/189) +- CSM and LCS plot function get a `scale_vectors` parameter. It scales the plotted coordinate system vectors when using + matplotlib as backend [[#293]](https://github.com/BAMWelDX/weldx/pull/293) ### fixes diff --git a/weldx/transformations/cs_manager.py b/weldx/transformations/cs_manager.py index aac9d61fc..974c017d0 100644 --- a/weldx/transformations/cs_manager.py +++ b/weldx/transformations/cs_manager.py @@ -1745,6 +1745,7 @@ def plot( time: types_time_and_lcs = None, time_ref: pd.Timestamp = None, axes_equal: bool = False, + scale_vectors: Union[float, List, np.ndarray] = None, show_data_labels: bool = True, show_labels: bool = True, show_origins: bool = True, @@ -1793,6 +1794,9 @@ def plot( axes_equal : (matplotlib only) If `True`, all axes are adjusted to cover an equally large range of value. That doesn't mean, that the limits are identical + scale_vectors : + (matplotlib only) A scaling factor or array to adjust the length of the + coordinate system vectors show_data_labels : (k3d only) If `True`, plotted data sets get labels with their names attached to them @@ -1850,6 +1854,7 @@ def plot( title=title, limits=limits, set_axes_equal=axes_equal, + scale_vectors=scale_vectors, show_origins=show_origins, show_trace=show_traces, show_vectors=show_vectors, diff --git a/weldx/transformations/local_cs.py b/weldx/transformations/local_cs.py index 1146d0390..62b1720cd 100644 --- a/weldx/transformations/local_cs.py +++ b/weldx/transformations/local_cs.py @@ -4,7 +4,7 @@ import warnings from copy import deepcopy -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING, List, Union import numpy as np import pandas as pd @@ -836,6 +836,7 @@ def plot( time: types_time_and_lcs = None, time_ref: pd.Timestamp = None, time_index: int = None, + scale_vectors: Union[float, List, np.ndarray] = None, show_origin: bool = True, show_trace: bool = True, show_vectors: bool = True, @@ -863,6 +864,8 @@ def plot( time_index: int If the coordinate system is time dependent, this parameter can be used to to select a specific key frame by its index. + scale_vectors : + A scaling factor or array to adjust the vector length show_origin: bool If `True`, a small dot with the assigned color will mark the coordinate systems' origin. @@ -883,6 +886,7 @@ def plot( time=time, time_ref=time_ref, time_index=time_index, + scale_vectors=scale_vectors, show_origin=show_origin, show_trace=show_trace, show_vectors=show_vectors, diff --git a/weldx/visualization/matplotlib_impl.py b/weldx/visualization/matplotlib_impl.py index 3f94ee9cb..8bb581469 100644 --- a/weldx/visualization/matplotlib_impl.py +++ b/weldx/visualization/matplotlib_impl.py @@ -95,6 +95,7 @@ def draw_coordinate_system_matplotlib( color: Any = None, label: str = None, time_idx: int = None, + scale_vectors: Union[float, List, np.ndarray] = None, show_origin: bool = True, show_vectors: bool = True, ): @@ -115,6 +116,8 @@ def draw_coordinate_system_matplotlib( time_idx : Selects time dependent data by index if the coordinate system has a time dependency. + scale_vectors : + A scaling factor or array to adjust the vector length show_origin : If `True`, the origin of the coordinate system will be highlighted in the color passed as another parameter @@ -137,10 +140,23 @@ def draw_coordinate_system_matplotlib( p_0 = dsx.coordinates if show_vectors: - orientation = dsx.orientation - p_x = p_0 + orientation[:, 0] - p_y = p_0 + orientation[:, 1] - p_z = p_0 + orientation[:, 2] + if scale_vectors is None: + tips = dsx.orientation + else: + if not isinstance(scale_vectors, np.ndarray): + if isinstance(scale_vectors, List): + scale_vectors = np.array(scale_vectors) + else: + scale_vectors = np.array([scale_vectors for _ in range(3)]) + + scale_mat = np.eye(3, 3) + for i in range(3): + scale_mat[i, i] = scale_vectors[i] + tips = np.matmul(scale_mat, dsx.orientation.data) + + p_x = p_0 + tips[:, 0] + p_y = p_0 + tips[:, 1] + p_z = p_0 + tips[:, 2] axes.plot([p_0[0], p_x[0]], [p_0[1], p_x[1]], [p_0[2], p_x[2]], "r") axes.plot([p_0[0], p_y[0]], [p_0[1], p_y[1]], [p_0[2], p_y[2]], "g") @@ -160,6 +176,7 @@ def plot_local_coordinate_system_matplotlib( time: types_timeindex = None, time_ref: pd.Timestamp = None, time_index: int = None, + scale_vectors: Union[float, List, np.ndarray] = None, show_origin: bool = True, show_trace: bool = True, show_vectors: bool = True, @@ -183,6 +200,8 @@ def plot_local_coordinate_system_matplotlib( `pandas.TimedeltaIndex` time_index : Index of a specific time step that should be plotted + scale_vectors : + A scaling factor or array to adjust the vector length show_origin : If `True`, the origin of the coordinate system will be highlighted in the color passed as another parameter @@ -212,6 +231,7 @@ def plot_local_coordinate_system_matplotlib( color=color, label=label, time_idx=i, + scale_vectors=scale_vectors, show_origin=show_origin, show_vectors=show_vectors, ) @@ -223,6 +243,7 @@ def plot_local_coordinate_system_matplotlib( color=color, label=label, time_idx=time_index, + scale_vectors=scale_vectors, show_origin=show_origin, show_vectors=show_vectors, ) @@ -333,6 +354,7 @@ def plot_coordinate_system_manager_matplotlib( time_ref: pd.Timestamp = None, title: str = None, limits: types_limits = None, + scale_vectors: Union[float, List, np.ndarray] = None, set_axes_equal: bool = False, show_origins: bool = True, show_trace: bool = True, @@ -374,6 +396,8 @@ def plot_coordinate_system_manager_matplotlib( Each tuple marks lower and upper boundary of the x, y and z axis. If only a single tuple is passed, the boundaries are used for all axis. If `None` is provided, the axis are adjusted to be of equal length. + scale_vectors : + A scaling factor or array to adjust the length of the coordinate system vectors set_axes_equal : (matplotlib only) If `True`, all axes are adjusted to cover an equally large range of value. That doesn't mean, that the limits are identical @@ -428,6 +452,7 @@ def plot_coordinate_system_manager_matplotlib( axes=axes, color=color, label=lcs_name, + scale_vectors=scale_vectors, show_origin=show_origins, show_trace=show_trace, show_vectors=show_vectors,