| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- import warnings
- warnings.filterwarnings('ignore')
- # Leer el archivo manualmente
- data = []
- with open('resultados1.txt', 'r', encoding='utf-8') as f:
- header = f.readline().strip().split('\t')
- for line in f:
- values = line.strip().split()
- if len(values) >= 15:
- data.append(values)
- # Convertir datos
- def convert_value(x):
- try:
- return float(x.replace(',', '.').strip())
- except:
- return np.nan
- tf = np.array([convert_value(row[2]) for row in data])
- tw = np.array([convert_value(row[3]) for row in data])
- flecha = np.array([convert_value(row[8]) for row in data])
- # Filtrar NaN
- valid = ~(np.isnan(tf) | np.isnan(tw) | np.isnan(flecha))
- tf = tf[valid]
- tw = tw[valid]
- flecha = flecha[valid]
- # Crear figura con 4 subplots
- fig = plt.figure(figsize=(18, 14))
- # Colores basados en la deflexión
- colors = plt.cm.RdYlGn_r((np.abs(flecha) - np.abs(flecha).min()) / (np.abs(flecha).max() - np.abs(flecha).min()))
- # 1. Vista 3D principal
- ax1 = fig.add_subplot(2, 2, 1, projection='3d')
- scatter1 = ax1.scatter(tf, tw, flecha, c=np.abs(flecha), cmap='RdYlGn_r',
- s=100, alpha=0.6, edgecolors='black', linewidth=0.5)
- ax1.set_xlabel('tf (ala)', fontweight='bold')
- ax1.set_ylabel('tw (alma)', fontweight='bold')
- ax1.set_zlabel('Flecha', fontweight='bold')
- ax1.set_title('Vista 3D Principal - Coloreado por |Deflexión|', fontweight='bold', fontsize=11)
- ax1.view_init(elev=20, azim=45)
- cbar1 = plt.colorbar(scatter1, ax=ax1, pad=0.1, shrink=0.8)
- cbar1.set_label('|Deflexión|', fontweight='bold')
- # 2. Vista 3D desde otro ángulo
- ax2 = fig.add_subplot(2, 2, 2, projection='3d')
- scatter2 = ax2.scatter(tf, tw, flecha, c=np.abs(flecha), cmap='RdYlGn_r',
- s=100, alpha=0.6, edgecolors='black', linewidth=0.5)
- ax2.set_xlabel('tf (ala)', fontweight='bold')
- ax2.set_ylabel('tw (alma)', fontweight='bold')
- ax2.set_zlabel('Flecha', fontweight='bold')
- ax2.set_title('Vista 3D Alternativa - Ángulo 225°', fontweight='bold', fontsize=11)
- ax2.view_init(elev=10, azim=225)
- # 3. Proyección 2D: tf vs tw (coloreado por flecha)
- ax3 = fig.add_subplot(2, 2, 3)
- scatter3 = ax3.scatter(tf, tw, c=np.abs(flecha), cmap='RdYlGn_r',
- s=150, alpha=0.7, edgecolors='black', linewidth=0.5)
- ax3.set_xlabel('tf - Espesor ala (mm)', fontweight='bold', fontsize=11)
- ax3.set_ylabel('tw - Espesor alma (mm)', fontweight='bold', fontsize=11)
- ax3.set_title('Proyección 2D: tf vs tw', fontweight='bold', fontsize=11)
- ax3.grid(True, alpha=0.3)
- cbar3 = plt.colorbar(scatter3, ax=ax3)
- cbar3.set_label('|Deflexión| (mm)', fontweight='bold')
- # 4. Gráfico de contorno 3D: Deflexión vs tf y tw
- ax4 = fig.add_subplot(2, 2, 4)
- # Crear grid para contorno
- tf_unique = np.sort(np.unique(tf))
- tw_unique = np.sort(np.unique(tw))
- # Crear matriz de valores Z (flecha)
- Z = np.full((len(tw_unique), len(tf_unique)), np.nan)
- for i, t_f in enumerate(tf_unique):
- for j, t_w in enumerate(tw_unique):
- mask = (tf == t_f) & (tw == t_w)
- if np.any(mask):
- Z[j, i] = np.abs(flecha[mask][0])
- # Graficar contorno
- X_grid, Y_grid = np.meshgrid(tf_unique, tw_unique)
- contour = ax4.contourf(X_grid, Y_grid, Z, levels=20, cmap='RdYlGn_r')
- contour_lines = ax4.contour(X_grid, Y_grid, Z, levels=10, colors='black', alpha=0.3, linewidths=0.5)
- ax4.clabel(contour_lines, inline=True, fontsize=8)
- ax4.set_xlabel('tf - Espesor ala (mm)', fontweight='bold', fontsize=11)
- ax4.set_ylabel('tw - Espesor alma (mm)', fontweight='bold', fontsize=11)
- ax4.set_title('Mapa de Contorno: |Deflexión|', fontweight='bold', fontsize=11)
- cbar4 = plt.colorbar(contour, ax=ax4)
- cbar4.set_label('|Deflexión| (mm)', fontweight='bold')
- plt.suptitle('Análisis Completo de la Frontera de Pareto - Sección de Viga',
- fontsize=14, fontweight='bold', y=0.995)
- plt.tight_layout(rect=[0, 0, 1, 0.99])
- plt.savefig('analisis_completo_pareto.png', dpi=300, bbox_inches='tight')
- print("✓ Visualización completa guardada como 'analisis_completo_pareto.png'")
- # Crear gráfico de superficies de respuesta
- fig2 = plt.figure(figsize=(16, 12))
- # 1. Superficie 3D de deflexión
- ax5 = fig2.add_subplot(2, 2, 1, projection='3d')
- surf1 = ax5.plot_surface(X_grid, Y_grid, Z, cmap='RdYlGn_r', alpha=0.8,
- edgecolor='none', antialiased=True)
- ax5.scatter(tf, tw, np.abs(flecha), c='black', s=20, alpha=0.3)
- ax5.set_xlabel('tf (mm)', fontweight='bold')
- ax5.set_ylabel('tw (mm)', fontweight='bold')
- ax5.set_zlabel('|Deflexión| (mm)', fontweight='bold')
- ax5.set_title('Superficie de Respuesta: |Deflexión|', fontweight='bold', fontsize=11)
- ax5.view_init(elev=25, azim=45)
- cbar5 = plt.colorbar(surf1, ax=ax5, pad=0.1, shrink=0.8)
- cbar5.set_label('|Deflexión| (mm)', fontweight='bold')
- # 2. Superficie 3D desde otro ángulo
- ax6 = fig2.add_subplot(2, 2, 2, projection='3d')
- surf2 = ax6.plot_surface(X_grid, Y_grid, Z, cmap='RdYlGn_r', alpha=0.8,
- edgecolor='none', antialiased=True)
- ax6.set_xlabel('tf (mm)', fontweight='bold')
- ax6.set_ylabel('tw (mm)', fontweight='bold')
- ax6.set_zlabel('|Deflexión| (mm)', fontweight='bold')
- ax6.set_title('Superficie de Respuesta - Vista Lateral', fontweight='bold', fontsize=11)
- ax6.view_init(elev=10, azim=120)
- # 3. Gráfico de dispersión con líneas de iso-deflexión
- ax7 = fig2.add_subplot(2, 2, 3)
- scatter7 = ax7.scatter(tf, tw, s=200, c=np.abs(flecha), cmap='RdYlGn_r',
- alpha=0.7, edgecolors='black', linewidth=1)
- contour7 = ax7.contour(X_grid, Y_grid, Z, levels=15, colors='gray', alpha=0.4, linewidths=0.8)
- ax7.clabel(contour7, inline=True, fontsize=7)
- ax7.set_xlabel('tf - Espesor ala (mm)', fontweight='bold', fontsize=11)
- ax7.set_ylabel('tw - Espesor alma (mm)', fontweight='bold', fontsize=11)
- ax7.set_title('Puntos de Diseño con Líneas de Iso-Deflexión', fontweight='bold', fontsize=11)
- ax7.grid(True, alpha=0.3)
- cbar7 = plt.colorbar(scatter7, ax=ax7)
- cbar7.set_label('|Deflexión| (mm)', fontweight='bold')
- # 4. Gráfico de efectos principales
- ax8 = fig2.add_subplot(2, 2, 4)
- tf_effect = [np.abs(flecha[tf == t_f]).mean() for t_f in tf_unique]
- tw_effect = [np.abs(flecha[tw == t_w]).mean() for t_w in tw_unique]
- ax8_2 = ax8.twinx()
- ax8.plot(tf_unique, tf_effect, 'b-o', linewidth=2, markersize=6, label='Efecto de tf')
- ax8_2.plot(tw_unique, tw_effect, 'r-s', linewidth=2, markersize=6, label='Efecto de tw')
- ax8.set_xlabel('Valor del parámetro (mm)', fontweight='bold', fontsize=11)
- ax8.set_ylabel('Deflexión media (tf)', color='b', fontweight='bold')
- ax8_2.set_ylabel('Deflexión media (tw)', color='r', fontweight='bold')
- ax8.set_title('Gráficos de Efectos Principales', fontweight='bold', fontsize=11)
- ax8.grid(True, alpha=0.3)
- ax8.tick_params(axis='y', labelcolor='b')
- ax8_2.tick_params(axis='y', labelcolor='r')
- lines1, labels1 = ax8.get_legend_handles_labels()
- lines2, labels2 = ax8_2.get_legend_handles_labels()
- ax8.legend(lines1 + lines2, labels1 + labels2, loc='upper left')
- plt.suptitle('Superficies de Respuesta y Análisis de Sensibilidad',
- fontsize=14, fontweight='bold', y=0.995)
- plt.tight_layout(rect=[0, 0, 1, 0.99])
- plt.savefig('superficies_respuesta.png', dpi=300, bbox_inches='tight')
- print("✓ Superficies de respuesta guardadas como 'superficies_respuesta.png'")
- print("\n✓ Análisis completado exitosamente")
- print(f" - {len(tf)} puntos analizados")
- print(f" - Valores tf: {tf.min():.4f} a {tf.max():.4f} mm")
- print(f" - Valores tw: {tw.min():.4f} a {tw.max():.4f} mm")
- print(f" - Deflexión: {np.abs(flecha).min():.2f} a {np.abs(flecha).max():.2f} mm")
- plt.show()
|