Skip to content

Commit

Permalink
dos modalidades de visor 3d utilizando las librerias Matplot y Ploty
Browse files Browse the repository at this point in the history
  • Loading branch information
dborja2021 authored Sep 23, 2024
1 parent cfedf15 commit b4b0a1d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pruebaMatlplot.py
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()
42 changes: 42 additions & 0 deletions pruebaPloty.py
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)

0 comments on commit b4b0a1d

Please sign in to comment.