trace_array = np.array(traza) x_coords = trace_array[:, 0] * con 256 coordenadas_y = trace_array[:, 1] * h / 256 ax.plot(x_coords, y_coords, ‘w-‘, linewidth=2, alpha=0.7) ax.plot(x_coords, y_coords, ‘c-‘, linewidth=1, alpha=0.9) para i, (x, y) en enumerate(zip(x_coords, y_coords)): color_idx = int(i * 9 / max(len(x_coords) – 1, 1)) ax.scatter(x, y, c=[self.colors[color_idx]], s=100, edgecolors=”blanco”, anchos de línea=2, zorder=5) ax.annotate(f'{i+1}’, (x, y), textcoords=”puntos de desplazamiento”, xytext=(5, 5), fontsize=10, color=”blanco”, fontweight=”bold”) ax.scatter(x_coords[0]y_coords[0]c=”lima”, s=200, marcador=”o”, edgecolors=”blanco”, anchos de línea=3, zorder=6, etiqueta=”Inicio”) ax.scatter(x_coords[-1]y_coords[-1]c=”rojo”, s=200, marcador=”X”, edgecolors=”blanco”, anchos de línea=3, zorder=6, label=”End”) ax.set_title(title, fontsize=14, fontweight=”bold”) ax.axis(‘off’) ax.legend(loc=”upper right”) plt.tight_layout() if save_path: plt.savefig(save_path, dpi=150, bbox_inches=”tight”) print(f”💾 Visualización guardada en {save_path}”) plt.show() def plot_action( self, action: Lista[float]action_labels: opcional[List[str]]= Ninguno, título: str = “Acción prevista del robot”, save_path: Opcional[str] = Ninguno) -> Ninguno: “””Trazar valores de acción como un gráfico de barras””” si action_labels es Ninguno: action_labels = [
‘Δx (forward)’, ‘Δy (left)’, ‘Δz (up)’,
‘Rx (roll)’, ‘Ry (pitch)’, ‘Rz (yaw)’,
‘Gripper’
]
higo, hacha = plt.subplots(tamaño de higo=(10, 5)) colores = [‘#3498db’, ‘#3498db’, ‘#3498db’,
‘#e74c3c’, ‘#e74c3c’, ‘#e74c3c’,
‘#2ecc71′]
x = np.arange(len(action)) bars = ax.bar(x, action, color=colors, edgecolor=”white”, linewidth=1.5) for bar, val in zip(bars, action): height = bar.get_height() ax.annotate(f'{val:.3f}’, xy=(bar.get_x() + bar.get_width() / 2, height), xytext=(0, 3 si altura >= 0 más -12), textcoords=”puntos de desplazamiento”, ha=”centro”, va=”abajo” si altura >= 0 más ‘arriba’, tamaño de fuente=9, peso de fuente=”bold”) ax.set_xticks(x) ax.set_xticklabels(action_labels, rotación=45, ha=”derecha”) ax.set_ylabel(‘Valor’, tamaño de fuente=12) ax.set_title(title, fontsize=14, fontweight=”bold”) ax.axhline(y=0, color=”gray”, linestyle=”–“, alpha=0.5) ax.grid(axis=”y”, alpha=0.3) de matplotlib.patches importar parche legend_elements = [
Patch(facecolor=”#3498db”, label=”Position”),
Patch(facecolor=”#e74c3c”, label=”Rotation”),
Patch(facecolor=”#2ecc71″, label=”Gripper”)
]
ax.legend(handles=legend_elements, loc=”arriba derecha”) plt.tight_layout() si save_path: plt.savefig(save_path, dpi=150, bbox_inches=”tight”) plt.show()