|
|
|
@ -10,7 +10,8 @@ def plot_xy(df, x_col, y_col, label:Optional[str] = None, ax=None,
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
marker: str = "o",
|
|
|
|
marker: str = "o",
|
|
|
|
linestyle: str = "-",):
|
|
|
|
linestyle: str = "-",
|
|
|
|
|
|
|
|
legen_loc=None,):
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Gráfica y vs x para un DataFrame.
|
|
|
|
Gráfica y vs x para un DataFrame.
|
|
|
|
@ -31,7 +32,9 @@ def plot_xy(df, x_col, y_col, label:Optional[str] = None, ax=None,
|
|
|
|
if ylim is not None:
|
|
|
|
if ylim is not None:
|
|
|
|
ax.set_ylim(ylim)
|
|
|
|
ax.set_ylim(ylim)
|
|
|
|
|
|
|
|
|
|
|
|
if label:
|
|
|
|
if legen_loc is not None:
|
|
|
|
|
|
|
|
ax.legend(loc=legen_loc)
|
|
|
|
|
|
|
|
elif label:
|
|
|
|
ax.legend()
|
|
|
|
ax.legend()
|
|
|
|
|
|
|
|
|
|
|
|
return ax
|
|
|
|
return ax
|
|
|
|
@ -41,7 +44,8 @@ def comparar_rondas(data: dict, experimento: int, x_col: str, y_col: str,
|
|
|
|
filter_fn: Optional[FilterFn] = None,
|
|
|
|
filter_fn: Optional[FilterFn] = None,
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
title: Optional[str] = None,):
|
|
|
|
title: Optional[str] = None,
|
|
|
|
|
|
|
|
legend_loc: Optional[str] = None,):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Compara el mismo experimento entre rondas:
|
|
|
|
Compara el mismo experimento entre rondas:
|
|
|
|
data[(ronda, experimento)] -> df
|
|
|
|
data[(ronda, experimento)] -> df
|
|
|
|
@ -57,10 +61,15 @@ def comparar_rondas(data: dict, experimento: int, x_col: str, y_col: str,
|
|
|
|
df = filter_fn(df)
|
|
|
|
df = filter_fn(df)
|
|
|
|
|
|
|
|
|
|
|
|
plot_xy(df, x_col, y_col, label=f"Ronda {ronda}", ax=ax,
|
|
|
|
plot_xy(df, x_col, y_col, label=f"Ronda {ronda}", ax=ax,
|
|
|
|
xlim=xlim, ylim=ylim)
|
|
|
|
xlim=xlim, ylim=ylim, legen_loc=legend_loc)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if title is "False":
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ax.set_title(title or f"Experimento {experimento} - Comparación de Rondas")
|
|
|
|
|
|
|
|
|
|
|
|
ax.set_title(title or f"Experimento {experimento} - Comparación de Rondas")
|
|
|
|
|
|
|
|
plt.show()
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
return fig, ax
|
|
|
|
return fig, ax
|
|
|
|
|
|
|
|
|
|
|
|
def comparar_experimentos(data: dict, ronda: int, x_col: str, y_col: str,
|
|
|
|
def comparar_experimentos(data: dict, ronda: int, x_col: str, y_col: str,
|
|
|
|
@ -70,6 +79,7 @@ def comparar_experimentos(data: dict, ronda: int, x_col: str, y_col: str,
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
title: Optional[str] = None,
|
|
|
|
title: Optional[str] = None,
|
|
|
|
|
|
|
|
legend_loc: Optional[str] = None,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Comparar varios experimentos dentro de una misma ronda.
|
|
|
|
Comparar varios experimentos dentro de una misma ronda.
|
|
|
|
@ -82,9 +92,11 @@ def comparar_experimentos(data: dict, ronda: int, x_col: str, y_col: str,
|
|
|
|
if filter_fn is not None:
|
|
|
|
if filter_fn is not None:
|
|
|
|
df = filter_fn(df)
|
|
|
|
df = filter_fn(df)
|
|
|
|
|
|
|
|
|
|
|
|
plot_xy(df, x_col, y_col, label=f"Experimento {exp}", ax=ax, xlim=xlim, ylim=ylim)
|
|
|
|
plot_xy(df, x_col, y_col, label=f"Experimento {exp}", ax=ax, xlim=xlim, ylim=ylim, legen_loc=legend_loc)
|
|
|
|
|
|
|
|
if title is "False":
|
|
|
|
ax.set_title(title or f"Ronda {ronda} - Comparación de Experimentos")
|
|
|
|
pass
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ax.set_title(title or f"Ronda {ronda} - Comparación de Experimentos")
|
|
|
|
|
|
|
|
|
|
|
|
if show is True:
|
|
|
|
if show is True:
|
|
|
|
plt.show()
|
|
|
|
plt.show()
|
|
|
|
@ -157,7 +169,7 @@ def plot_color_map(df, x_col: str, y_col: str, z_col: str,
|
|
|
|
plt.show()
|
|
|
|
plt.show()
|
|
|
|
return fig, ax
|
|
|
|
return fig, ax
|
|
|
|
|
|
|
|
|
|
|
|
def plot_dual_axis(df, x_col: str, y1_col: str, y2_col: str,
|
|
|
|
def plot_dual_axis(df, x_col: str, y1_col: str, y2_col: str, ax=None,
|
|
|
|
label1: Optional[str] = None,
|
|
|
|
label1: Optional[str] = None,
|
|
|
|
label2: Optional[str] = None,
|
|
|
|
label2: Optional[str] = None,
|
|
|
|
title: Optional[str] = None,
|
|
|
|
title: Optional[str] = None,
|
|
|
|
@ -167,8 +179,13 @@ def plot_dual_axis(df, x_col: str, y1_col: str, y2_col: str,
|
|
|
|
Gráfica con doble eje Y:
|
|
|
|
Gráfica con doble eje Y:
|
|
|
|
y1 vs x (izquierda) y y2 vs x (derecha)
|
|
|
|
y1 vs x (izquierda) y y2 vs x (derecha)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
fig, ax1 = plt.subplots(figsize=(7, 5))
|
|
|
|
if ax is None:
|
|
|
|
ax2 = ax1.twinx()
|
|
|
|
fig, ax1 = plt.subplots(figsize=(7, 5))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ax1 = ax
|
|
|
|
|
|
|
|
fig = ax1.figure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ax2 = ax1.twinx()
|
|
|
|
|
|
|
|
|
|
|
|
ax1.plot(df[x_col], df[y1_col], marker="o", linestyle="-", color="b",label= label1 or y1_col)
|
|
|
|
ax1.plot(df[x_col], df[y1_col], marker="o", linestyle="-", color="b",label= label1 or y1_col)
|
|
|
|
ax2.plot(df[x_col], df[y2_col], marker="s", linestyle="--", color="r",label= label2 or y2_col)
|
|
|
|
ax2.plot(df[x_col], df[y2_col], marker="s", linestyle="--", color="r",label= label2 or y2_col)
|
|
|
|
@ -178,6 +195,7 @@ def plot_dual_axis(df, x_col: str, y1_col: str, y2_col: str,
|
|
|
|
ax2.set_ylabel(y2_col)
|
|
|
|
ax2.set_ylabel(y2_col)
|
|
|
|
|
|
|
|
|
|
|
|
ax1.grid(True)
|
|
|
|
ax1.grid(True)
|
|
|
|
|
|
|
|
|
|
|
|
ax1.set_title(title or f"{y1_col} y {y2_col} vs {x_col}")
|
|
|
|
ax1.set_title(title or f"{y1_col} y {y2_col} vs {x_col}")
|
|
|
|
|
|
|
|
|
|
|
|
# Leyendas Combinadas
|
|
|
|
# Leyendas Combinadas
|
|
|
|
@ -234,3 +252,79 @@ def sombrear_zonas(ax, limites, colores=None, alpha=0.15):
|
|
|
|
alpha=alpha
|
|
|
|
alpha=alpha
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def percent_change(data:dict, ronda: int, x_col: str, y_col: str,
|
|
|
|
|
|
|
|
experimentos: Iterable[int] = (1,2,3,4),
|
|
|
|
|
|
|
|
show: bool = False,
|
|
|
|
|
|
|
|
btween_exp: bool = False,
|
|
|
|
|
|
|
|
filter_fn: Optional[FilterFn] = None,
|
|
|
|
|
|
|
|
xlim: Optional[Tuple[float, float]] = None,
|
|
|
|
|
|
|
|
ylim: Optional[Tuple[float, float]] = None,
|
|
|
|
|
|
|
|
title: Optional[str] = None, ):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig, ax = plt.subplots(figsize=(7,5))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if btween_exp is False:
|
|
|
|
|
|
|
|
change_value = {}
|
|
|
|
|
|
|
|
sum_mean = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for exp in experimentos:
|
|
|
|
|
|
|
|
df = data[(ronda, exp)]
|
|
|
|
|
|
|
|
if filter_fn is not None:
|
|
|
|
|
|
|
|
df = filter_fn(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
R = df[y_col].values
|
|
|
|
|
|
|
|
x_ = df[x_col].values
|
|
|
|
|
|
|
|
for i in range(len(R) - 1):
|
|
|
|
|
|
|
|
change_value[i] = ((R[i+1] - R[i]) / R[i]) * 100
|
|
|
|
|
|
|
|
pct = change_value[i]
|
|
|
|
|
|
|
|
sum_mean = sum_mean + abs(pct)
|
|
|
|
|
|
|
|
print(f"Δ% Experiment:{exp} between data {i} and {i+1}: {pct:.2f}%")
|
|
|
|
|
|
|
|
if show is True:
|
|
|
|
|
|
|
|
ax.annotate(f"{pct:.1f}%",
|
|
|
|
|
|
|
|
(x_[i+1], R[i+1]),
|
|
|
|
|
|
|
|
textcoords="offset points",
|
|
|
|
|
|
|
|
xytext=(0,8),
|
|
|
|
|
|
|
|
ha='center',
|
|
|
|
|
|
|
|
fontsize=8,
|
|
|
|
|
|
|
|
color="red")
|
|
|
|
|
|
|
|
mean = sum_mean/len(change_value)
|
|
|
|
|
|
|
|
change_mx_min = ((R[(len(R)-1)] - R[0])/R[0]) * 100
|
|
|
|
|
|
|
|
print(f"Last_Value:{R[(len(R)-1)]:.3f} Fst_value:{R[0]:.3f}")
|
|
|
|
|
|
|
|
print(f"The mean percent change value in Experiment {exp} are : {mean:.2f}%")
|
|
|
|
|
|
|
|
print(f"The percent change between the last and first value of experiment {exp}: {change_mx_min:.2f}%")
|
|
|
|
|
|
|
|
plot_xy(df, x_col, y_col, label=f"Experimento {exp}", ax=ax, xlim=xlim, ylim=ylim)
|
|
|
|
|
|
|
|
sum_mean = 0
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
change_value = {}
|
|
|
|
|
|
|
|
df = {}
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
|
|
|
for exp in experimentos:
|
|
|
|
|
|
|
|
df[i] = data[(ronda, exp)]
|
|
|
|
|
|
|
|
if filter_fn is not None:
|
|
|
|
|
|
|
|
df[i] = filter_fn(df[i])
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
R1 = df[0][y_col].values
|
|
|
|
|
|
|
|
R2 = df[1][y_col].values
|
|
|
|
|
|
|
|
x_1 = df[0][x_col].values
|
|
|
|
|
|
|
|
x_2 = df[1][x_col].values
|
|
|
|
|
|
|
|
for x in range(len(R1)):
|
|
|
|
|
|
|
|
change_value[x] = ((R2[x] - R1[x]) / R1[x]) * 100
|
|
|
|
|
|
|
|
pct = change_value[x]
|
|
|
|
|
|
|
|
print(f"Δ% Punto {x}: Exp{experimentos[0]} vs Exp{experimentos[1]} = {pct:.2f}%")
|
|
|
|
|
|
|
|
if show is True:
|
|
|
|
|
|
|
|
# Line that connect each point
|
|
|
|
|
|
|
|
ax.plot([x_1[x], x_2[x]], [R1[x], R2[x]], color="black", linestyle="-", linewidth=1)
|
|
|
|
|
|
|
|
# Text with the change percent in the middle of the line
|
|
|
|
|
|
|
|
ax.annotate(f"{pct:.1f}%",
|
|
|
|
|
|
|
|
xy=((x_1[x]+x_2[x])/2, (R1[x]+R2[x])/2),
|
|
|
|
|
|
|
|
textcoords="offset points",
|
|
|
|
|
|
|
|
xytext=(0,3),
|
|
|
|
|
|
|
|
ha='center', fontsize=8, color="red")
|
|
|
|
|
|
|
|
plot_xy(df[0], x_col, y_col, label=f"Experimento {experimentos[0]}", ax=ax, xlim=xlim, ylim=ylim)
|
|
|
|
|
|
|
|
plot_xy(df[1], x_col, y_col, label=f"Experimento {experimentos[1]}", ax=ax, xlim=xlim, ylim=ylim)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ax.set_title(title or f"Round {ronda} - Experiments Comparative")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if show is True:
|
|
|
|
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
return fig, ax
|