From 88e6b532a96ca5df828b35db74bfe5fb9c44ebff Mon Sep 17 00:00:00 2001 From: Miguel de la Varga Date: Wed, 29 Oct 2025 13:57:53 +0100 Subject: [PATCH] [ENH] Add customization options for surface points and orientations drawing Introduce `kwargs_surface_points` and `kwargs_orientations` to allow overriding default settings in 2D plot rendering. Updated `_plot_2d_sections_api` and `drawer_input_2d` to support these additional parameters, enabling more flexible visualization customization --- gempy_viewer/API/_plot_2d_sections_api.py | 8 ++- .../modules/plot_2d/drawer_input_2d.py | 53 +++++++++++++------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/gempy_viewer/API/_plot_2d_sections_api.py b/gempy_viewer/API/_plot_2d_sections_api.py index 52dd9cd..9722c31 100644 --- a/gempy_viewer/API/_plot_2d_sections_api.py +++ b/gempy_viewer/API/_plot_2d_sections_api.py @@ -24,10 +24,14 @@ def plot_sections(gempy_model: GeoModel, sections_data: list[SectionData2D], dat kwargs_scalar_field: dict = None, kwargs_lithology: dict = None, kwargs_boundaries: dict = None, + kwargs_surface_points: dict = None, + kwargs_orientations: dict = None, ): kwargs_lithology = kwargs_lithology if kwargs_lithology is not None else {} kwargs_scalar_field = kwargs_scalar_field if kwargs_scalar_field is not None else {} kwargs_topography = kwargs_topography if kwargs_topography is not None else {} + kwargs_surface_points = kwargs_surface_points if kwargs_surface_points is not None else {} + kwargs_orientations = kwargs_orientations if kwargs_orientations is not None else {} series_n = series_n if series_n is not None else [0] @@ -43,7 +47,9 @@ def plot_sections(gempy_model: GeoModel, sections_data: list[SectionData2D], dat orientations_colors=gempy_model.structural_frame.orientations_colors_per_item, orientations=gempy_model.orientations_copy.df.copy(), points=gempy_model.surface_points_copy.df.copy(), - slicer_data=section_data.slicer_data + slicer_data=section_data.slicer_data, + kwargs_surface_points=kwargs_surface_points, + kwargs_orientations=kwargs_orientations, ) if data_to_show.show_lith[e] is True: diff --git a/gempy_viewer/modules/plot_2d/drawer_input_2d.py b/gempy_viewer/modules/plot_2d/drawer_input_2d.py index 89ba523..53b9643 100644 --- a/gempy_viewer/modules/plot_2d/drawer_input_2d.py +++ b/gempy_viewer/modules/plot_2d/drawer_input_2d.py @@ -15,41 +15,60 @@ # TODO: This could be public and the slice just a class yes! def draw_data(ax, surface_points_colors: list[str], orientations_colors: list[str], - orientations: 'pd.DataFrame', points: 'pd.DataFrame', slicer_data: SlicerData): + orientations: 'pd.DataFrame', points: 'pd.DataFrame', slicer_data: SlicerData, + kwargs_surface_points: dict = None, + kwargs_orientations: dict = None): - _draw_surface_points(ax, points, slicer_data, surface_points_colors) - _draw_orientations(ax, orientations, orientations_colors, slicer_data) + kwargs_surface_points = kwargs_surface_points if kwargs_surface_points is not None else {} + kwargs_orientations = kwargs_orientations if kwargs_orientations is not None else {} + + _draw_surface_points(ax, points, slicer_data, surface_points_colors, **kwargs_surface_points) + _draw_orientations(ax, orientations, orientations_colors, slicer_data, **kwargs_orientations) -def _draw_orientations(ax, orientations, orientations_colors, slicer_data): +def _draw_orientations(ax, orientations, orientations_colors, slicer_data, **kwargs): sel_ori = orientations[slicer_data.select_projected_o] aspect = np.subtract(*ax.get_ylim()) / np.subtract(*ax.get_xlim()) min_axis = 'width' if aspect < 1 else 'height' + + # Default values that can be overridden by kwargs + default_kwargs = { + 'pivot': 'tail', + 'scale_units': min_axis, + 'scale': 30, + 'color': np.array(orientations_colors)[slicer_data.select_projected_o], + 'edgecolor': 'k', + 'headwidth': 8, + 'linewidths': 1, + 'zorder': 102 + } + default_kwargs.update(kwargs) + ax.quiver( sel_ori[slicer_data.x], sel_ori[slicer_data.y], sel_ori[slicer_data.Gx], sel_ori[slicer_data.Gy], - pivot="tail", - scale_units=min_axis, - scale=30, - color=np.array(orientations_colors)[slicer_data.select_projected_o], - edgecolor='k', - headwidth=8, - linewidths=1, - zorder=102 + **default_kwargs ) -def _draw_surface_points(ax, points, slicer_data, surface_points_colors): +def _draw_surface_points(ax, points, slicer_data, surface_points_colors, **kwargs): points_df = points[slicer_data.select_projected_p] + + # Default values that can be overridden by kwargs + default_kwargs = { + 'c': np.array(surface_points_colors)[slicer_data.select_projected_p], + 's': 70, + 'edgecolors': 'white', + 'zorder': 102 + } + default_kwargs.update(kwargs) + ax.scatter( points_df[slicer_data.x], points_df[slicer_data.y], - c=(np.array(surface_points_colors)[slicer_data.select_projected_p]), - s=70, - edgecolors='white', - zorder=102 + **default_kwargs )