Skip to content

Commit bc299aa

Browse files
committed
Refactor 3D plotting utilities and improve color mapping.
Reordered actor assignment for scalar bars, corrected colormap flipping logic, and updated scalar range handling. Enhanced surface plotting with custom colormap support and fixed lithology scalar data calculation. These changes improve clarity, functionality, and visual consistency in 3D plots.
1 parent 8586c7d commit bc299aa

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

gempy_viewer/modules/plot_3d/drawer_input_3d.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from gempy.core.data import GeoModel
44
from gempy.core.data.orientations import OrientationsTable
55
from gempy.core.data.surface_points import SurfacePointsTable
6+
from matplotlib.colors import ListedColormap
7+
68
from gempy_viewer.modules.plot_2d.plot_2d_utils import get_geo_model_cmap
79
from gempy_viewer.modules.plot_3d.vista import GemPyToVista
810
from gempy_viewer.optional_dependencies import require_pyvista
@@ -22,7 +24,8 @@ def plot_data(gempy_vista: GemPyToVista,
2224

2325
plot_surface_points(
2426
gempy_vista=gempy_vista,
25-
surface_points=surface_points_copy
27+
surface_points=surface_points_copy,
28+
element_colors=model.structural_frame.elements_colors
2629
)
2730

2831
plot_orientations(
@@ -37,6 +40,7 @@ def plot_surface_points(
3740
gempy_vista: GemPyToVista,
3841
surface_points: SurfacePointsTable,
3942
render_points_as_spheres=True,
43+
element_colors=None,
4044
point_size=10
4145
):
4246
# Selecting the surfaces to plot
@@ -53,14 +57,17 @@ def plot_surface_points(
5357
vectorize_ids = _vectorize_ids(ids, ids)
5458
poly['id'] = vectorize_ids
5559

60+
custom_cmap = ListedColormap(element_colors)
61+
5662
gempy_vista.surface_points_mesh = poly
5763
gempy_vista.surface_points_actor = gempy_vista.p.add_mesh(
5864
mesh=poly,
5965
scalars='id',
6066
render_points_as_spheres=render_points_as_spheres,
6167
point_size=point_size,
6268
show_scalar_bar=False,
63-
# clim=(0, ids.max())
69+
cmap=custom_cmap,
70+
clim=(0, np.unique(vectorize_ids).shape[0])
6471
)
6572

6673

gempy_viewer/modules/plot_3d/drawer_structured_grid_3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def set_scalar_data(
100100
# Substitute the madness of the previous if with match
101101
match scalar_data_type:
102102
case ScalarDataType.LITHOLOGY | ScalarDataType.ALL:
103-
max_lith = data.n_surfaces + 1 # (for basement)
103+
max_lith = data.n_surfaces # (for basement)
104104
block_ = max_lith - (data.lith_block - 1)
105105
structured_grid.cell_data['id'] = block_
106106
case ScalarDataType.SCALAR_FIELD | ScalarDataType.ALL:

gempy_viewer/modules/plot_3d/plot_3d_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def set_scalar_bar(gempy_vista: GemPyToVista, elements_names: list[str],
4040
import pyvista as pv
4141

4242
# Get mapper actor
43-
if gempy_vista.surface_points_actor is not None:
44-
mapper_actor: pv.Actor = gempy_vista.surface_points_actor
45-
elif gempy_vista.regular_grid_actor is not None:
43+
if gempy_vista.regular_grid_actor is not None:
4644
mapper_actor = gempy_vista.regular_grid_actor
45+
elif gempy_vista.surface_points_actor is not None:
46+
mapper_actor: pv.Actor = gempy_vista.surface_points_actor
4747
else:
4848
return None # * Not a good mapper for the scalar bar
4949

@@ -71,7 +71,7 @@ def set_scalar_bar(gempy_vista: GemPyToVista, elements_names: list[str],
7171

7272
custom_cmap = ListedColormap(custom_colors)
7373
# Apply the custom colormap to the lookup table
74-
lut.apply_cmap(cmap=custom_cmap, n_values=n_colors, flip=True)
74+
lut.apply_cmap(cmap=custom_cmap, n_values=n_colors, flip=False)
7575

7676
else:
7777
# Apply a default colormap if no custom colors are provided
@@ -81,6 +81,7 @@ def set_scalar_bar(gempy_vista: GemPyToVista, elements_names: list[str],
8181
sargs = gempy_vista.scalar_bar_arguments
8282
min_id, max_id = surfaces_ids.min(), surfaces_ids.max()
8383
mapper_actor.mapper.scalar_range = (min_id - .4, max_id + .5)
84+
8485
sargs["mapper"] = mapper_actor.mapper
8586
sargs["n_labels"] = 0
8687

0 commit comments

Comments
 (0)