hedtorresca commited on
Commit
3750970
·
verified ·
1 Parent(s): 25e8ced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -140,20 +140,28 @@ def grafico_univariado(var, genero, localidades, compromiso_renal, antecedentes)
140
  # Gráfico bivariado
141
  def grafico_bivariado(x, y, genero, localidades, compromiso_renal, antecedentes):
142
  df = aplicar_filtros(data, genero, localidades, compromiso_renal, antecedentes)
143
- if df.empty:
144
  return None
145
  plt.figure(figsize=(6, 4))
146
- if df[x].dtype == 'object' or df[y].dtype == 'object':
147
- sns.countplot(data=df, x=x, hue=y)
148
- else:
149
  sns.scatterplot(data=df, x=x, y=y)
 
 
 
 
 
 
 
 
 
 
150
  plt.title(f"{x} vs {y}")
151
- path = f"bi_{x}_{y}.png"
152
  plt.tight_layout()
 
153
  plt.savefig(path)
154
  plt.close()
155
  return path
156
-
157
  # Interfaz
158
  def lanzar_app():
159
  with gr.Blocks() as demo:
 
140
  # Gráfico bivariado
141
  def grafico_bivariado(x, y, genero, localidades, compromiso_renal, antecedentes):
142
  df = aplicar_filtros(data, genero, localidades, compromiso_renal, antecedentes)
143
+ if df.empty or x not in df.columns or y not in df.columns:
144
  return None
145
  plt.figure(figsize=(6, 4))
146
+ if pd.api.types.is_numeric_dtype(df[x]) and pd.api.types.is_numeric_dtype(df[y]):
 
 
147
  sns.scatterplot(data=df, x=x, y=y)
148
+ elif pd.api.types.is_numeric_dtype(df[x]) and not pd.api.types.is_numeric_dtype(df[y]):
149
+ sns.boxplot(data=df, x=y, y=x)
150
+ plt.xticks(rotation=30)
151
+ elif pd.api.types.is_numeric_dtype(df[y]) and not pd.api.types.is_numeric_dtype(df[x]):
152
+ sns.boxplot(data=df, x=x, y=y)
153
+ plt.xticks(rotation=30)
154
+ else:
155
+ orden_x = df[x].value_counts().index
156
+ sns.countplot(data=df, x=x, hue=y, order=orden_x)
157
+ plt.xticks(rotation=30)
158
  plt.title(f"{x} vs {y}")
 
159
  plt.tight_layout()
160
+ path = f"bi_{x}_{y}.png"
161
  plt.savefig(path)
162
  plt.close()
163
  return path
164
+
165
  # Interfaz
166
  def lanzar_app():
167
  with gr.Blocks() as demo: