Skip to content

Commit b3fdce6

Browse files
authored
[ENH] Add customization options for surface points and orientations drawing (#12)
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
2 parents 7a873f3 + c084e18 commit b3fdce6

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

gempy_viewer/API/_plot_2d_sections_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ def plot_sections(gempy_model: GeoModel, sections_data: list[SectionData2D], dat
2424
kwargs_scalar_field: dict = None,
2525
kwargs_lithology: dict = None,
2626
kwargs_boundaries: dict = None,
27+
kwargs_surface_points: dict = None,
28+
kwargs_orientations: dict = None,
2729
):
2830
kwargs_lithology = kwargs_lithology if kwargs_lithology is not None else {}
2931
kwargs_scalar_field = kwargs_scalar_field if kwargs_scalar_field is not None else {}
3032
kwargs_topography = kwargs_topography if kwargs_topography is not None else {}
33+
kwargs_surface_points = kwargs_surface_points if kwargs_surface_points is not None else {}
34+
kwargs_orientations = kwargs_orientations if kwargs_orientations is not None else {}
3135

3236
series_n = series_n if series_n is not None else [0]
3337

@@ -43,7 +47,9 @@ def plot_sections(gempy_model: GeoModel, sections_data: list[SectionData2D], dat
4347
orientations_colors=gempy_model.structural_frame.orientations_colors_per_item,
4448
orientations=gempy_model.orientations_copy.df.copy(),
4549
points=gempy_model.surface_points_copy.df.copy(),
46-
slicer_data=section_data.slicer_data
50+
slicer_data=section_data.slicer_data,
51+
kwargs_surface_points=kwargs_surface_points,
52+
kwargs_orientations=kwargs_orientations,
4753
)
4854

4955
if data_to_show.show_lith[e] is True:

gempy_viewer/modules/plot_2d/drawer_contours_2d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ def plot_regular_grid_contacts(gempy_model: GeoModel, ax: matplotlib.axes.Axes,
1616
kwargs = {}
1717

1818
zorder = kwargs.get('zorder', 100)
19+
contour_colors = kwargs.get('contour_colors', None)
1920

2021
shape = resolution
2122
c_id = 0 # * color id startpoint
22-
all_colors = gempy_model.structural_frame.elements_colors_contacts
23+
all_colors = contour_colors if contour_colors is not None else gempy_model.structural_frame.elements_colors_contacts
2324

2425
for e, block in enumerate(gempy_model.solutions.raw_arrays.scalar_field_matrix):
2526
_scalar_field_per_surface = np.where(gempy_model.solutions.raw_arrays.scalar_field_at_surface_points[e] != 0)

gempy_viewer/modules/plot_2d/drawer_input_2d.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,60 @@
1515

1616
# TODO: This could be public and the slice just a class yes!
1717
def draw_data(ax, surface_points_colors: list[str], orientations_colors: list[str],
18-
orientations: 'pd.DataFrame', points: 'pd.DataFrame', slicer_data: SlicerData):
18+
orientations: 'pd.DataFrame', points: 'pd.DataFrame', slicer_data: SlicerData,
19+
kwargs_surface_points: dict = None,
20+
kwargs_orientations: dict = None):
1921

20-
_draw_surface_points(ax, points, slicer_data, surface_points_colors)
21-
_draw_orientations(ax, orientations, orientations_colors, slicer_data)
22+
kwargs_surface_points = kwargs_surface_points if kwargs_surface_points is not None else {}
23+
kwargs_orientations = kwargs_orientations if kwargs_orientations is not None else {}
24+
25+
_draw_surface_points(ax, points, slicer_data, surface_points_colors, **kwargs_surface_points)
26+
_draw_orientations(ax, orientations, orientations_colors, slicer_data, **kwargs_orientations)
2227

2328

24-
def _draw_orientations(ax, orientations, orientations_colors, slicer_data):
29+
def _draw_orientations(ax, orientations, orientations_colors, slicer_data, **kwargs):
2530
sel_ori = orientations[slicer_data.select_projected_o]
2631
aspect = np.subtract(*ax.get_ylim()) / np.subtract(*ax.get_xlim())
2732
min_axis = 'width' if aspect < 1 else 'height'
33+
34+
# Default values that can be overridden by kwargs
35+
default_kwargs = {
36+
'pivot': 'tail',
37+
'scale_units': min_axis,
38+
'scale': 30,
39+
'color': np.array(orientations_colors)[slicer_data.select_projected_o],
40+
'edgecolor': 'k',
41+
'headwidth': 8,
42+
'linewidths': 1,
43+
'zorder': 102
44+
}
45+
default_kwargs.update(kwargs)
46+
2847
ax.quiver(
2948
sel_ori[slicer_data.x],
3049
sel_ori[slicer_data.y],
3150
sel_ori[slicer_data.Gx],
3251
sel_ori[slicer_data.Gy],
33-
pivot="tail",
34-
scale_units=min_axis,
35-
scale=30,
36-
color=np.array(orientations_colors)[slicer_data.select_projected_o],
37-
edgecolor='k',
38-
headwidth=8,
39-
linewidths=1,
40-
zorder=102
52+
**default_kwargs
4153
)
4254

4355

44-
def _draw_surface_points(ax, points, slicer_data, surface_points_colors):
56+
def _draw_surface_points(ax, points, slicer_data, surface_points_colors, **kwargs):
4557
points_df = points[slicer_data.select_projected_p]
58+
59+
# Default values that can be overridden by kwargs
60+
default_kwargs = {
61+
'c': np.array(surface_points_colors)[slicer_data.select_projected_p],
62+
's': 70,
63+
'edgecolors': 'white',
64+
'zorder': 102
65+
}
66+
default_kwargs.update(kwargs)
67+
4668
ax.scatter(
4769
points_df[slicer_data.x],
4870
points_df[slicer_data.y],
49-
c=(np.array(surface_points_colors)[slicer_data.select_projected_p]),
50-
s=70,
51-
edgecolors='white',
52-
zorder=102
71+
**default_kwargs
5372
)
5473

5574

requirements/dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ gempy
55
imagehash
66
pillow
77
pydantic
8-
gempy_engine>=2025.2.0dev0,<2025.3.0
98
gempy>=2025.2.0dev0,<2025.3.0

requirements/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
matplotlib
22
numpy
3-
gempy_engine>=2025.3dev0

0 commit comments

Comments
 (0)