import matplotlib.pyplot as plt

# Datos de flujo másico, potencia eléctrica y térmica
mass_flow = [0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18]
electric_power = [1.542, 1.647, 1.682, 1.699, 1.709, 1.716, 1.721, 1.725, 1.728]
thermal_power = [5.4, 5.351, 5.332, 5.322, 5.316, 5.312, 5.309, 5.306, 5.305]

# Tamaños de letra personalizables
title_fontsize = 22
axis_label_fontsize = 20
tick_label_fontsize = 20
legend_fontsize = 20

# Definir manualmente los rangos de los ejes Y
electric_power_min = 1.5
electric_power_max = 1.75
thermal_power_min = 5.30
thermal_power_max = 5.44

# Crear una figura y ejes
fig, ax1 = plt.subplots(figsize=(12, 8))

# Graficar potencia eléctrica
ax1.plot(mass_flow, electric_power, marker='o', color='blue', linestyle='-', linewidth=2, label='Electric power')
ax1.set_ylabel('Power (kW)', fontsize=axis_label_fontsize)
ax1.tick_params(axis='both', labelsize=tick_label_fontsize)
ax1.set_xlabel('Mass Flow of HTF (kg/s)', fontsize=axis_label_fontsize)
ax1.set_ylim(electric_power_min, electric_power_max)  # Ajuste manual del límite del eje Y izquierdo

# Ajustar los límites y ticks del eje X con márgenes
x_margin = 0.01  # Márgenes en el eje X
ax1.set_xlim(min(mass_flow) - x_margin, max(mass_flow) + x_margin)  # Añadir márgenes a la izquierda y derecha
ax1.set_xticks(mass_flow)  # Asegurar que los ticks coincidan con los datos

# Crear segundo eje Y para la potencia térmica
ax2 = ax1.twinx()
ax2.plot(mass_flow, thermal_power, marker='s', color='red', linestyle='-', linewidth=2, label='Thermal power')
ax2.set_ylabel('Power (kW)', fontsize=axis_label_fontsize)
ax2.set_ylim(thermal_power_min, thermal_power_max)  # Ajuste manual del límite del eje Y derecho
ax2.tick_params(axis='y', labelsize=tick_label_fontsize)

# Título del gráfico
plt.title('', fontsize=title_fontsize)

# Integrar leyendas en un solo cuadro a la izquierda
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper left', fontsize=legend_fontsize, frameon=True)

# Acentuar el marco del gráfico
for spine in ax1.spines.values():
    spine.set_edgecolor('black')
    spine.set_linewidth(2)

for spine in ax2.spines.values():
    spine.set_edgecolor('black')
    spine.set_linewidth(2)

# Ajustar el diseño
fig.tight_layout()

# Mostrar el gráfico
plt.show()

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: