-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dos modalidades de visor 3d utilizando las librerias Matplot y Ploty
- Loading branch information
1 parent
cfedf15
commit b4b0a1d
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.mplot3d import Axes3D | ||
from matplotlib.widgets import Slider | ||
import numpy as np | ||
|
||
# Coordenadas de los puntos que quieres dibujar | ||
x = np.array([1, 2, 3, 4, 5]) | ||
y = np.array([1, 2, 3, 4, 5]) | ||
z = np.array([1, 4, 9, 16, 25]) | ||
|
||
# Colores de los puntos | ||
colors = np.array(['r', 'g', 'b', 'y', 'm']) # r: rojo, g: verde, b: azul, y: amarillo, m: magenta | ||
|
||
# Crear la figura y el eje 3D | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
scatter = ax.scatter(x, y, z, c=colors) | ||
|
||
# Añadir un slider para manejar la escala | ||
ax_slider = plt.axes([0.25, 0.1, 0.65, 0.03]) | ||
slider = Slider(ax_slider, 'Escala', 0.1, 2.0, valinit=1.0) | ||
|
||
def update(val): | ||
scale = slider.val | ||
ax.clear() | ||
ax.scatter(x, y, z, c=colors) | ||
ax.set_xlim([min(x) * scale, max(x) * scale]) | ||
ax.set_ylim([min(y) * scale, max(y) * scale]) | ||
ax.set_zlim([min(z) * scale, max(z) * scale]) | ||
plt.draw() | ||
|
||
slider.on_changed(update) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import numpy as np | ||
import plotly.graph_objects as go | ||
import plotly.io as pio | ||
|
||
# Puedes probar diferentes renderizadores según tu entorno | ||
# pio.renderers.default = 'notebook' # Intenta con 'inline' si estás en Jupyter | ||
|
||
# Función para convertir RGB a formato hexadecimal | ||
def rgb_to_hex(r, g, b): | ||
# Asegurarse de que los valores r, g, b sean enteros | ||
r, g, b = int(r), int(g), int(b) | ||
return f'#{r:02x}{g:02x}{b:02x}' | ||
|
||
# Función que genera un gráfico 3D con Plotly | ||
def plot_lidar_data(x_vals, y_vals, z_vals, colors): | ||
fig = go.Figure(data=[go.Scatter3d( | ||
x=x_vals, | ||
y=y_vals, | ||
z=z_vals, | ||
mode='markers', | ||
marker=dict( | ||
size=2, | ||
color=colors, | ||
) | ||
)]) | ||
|
||
fig.update_layout(scene=dict( | ||
xaxis_title='X', | ||
yaxis_title='Y', | ||
zaxis_title='Z' | ||
)) | ||
|
||
fig.show() | ||
|
||
# Ejemplo de datos personalizados | ||
x_vals = [10, 20, 30, 40, 50] | ||
y_vals = [10, 25, 35, 45, 55] | ||
z_vals = [10, 30, 40, 50, 60] | ||
colors = [rgb_to_hex(255, 0, 0), rgb_to_hex(0, 255, 0), rgb_to_hex(0, 0, 255), rgb_to_hex(255, 255, 0), rgb_to_hex(0, 255, 255)] | ||
|
||
# Llamada a la función para generar el gráfico | ||
plot_lidar_data(x_vals, y_vals, z_vals, colors) |