Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,6 @@ def calculate_y_range(y_values):
|
|
| 23 |
# Función para convertir HEX a RGBA con transparencia
|
| 24 |
def hex_to_rgba(hex, alpha=1.0):
|
| 25 |
hex = hex.lstrip('#')
|
| 26 |
-
hlen = len(hex)
|
| 27 |
return f'rgba({int(hex[0:2], 16)},{int(hex[2:4], 16)},{int(hex[4:6], 16)},{alpha})'
|
| 28 |
|
| 29 |
# Colores predefinidos
|
|
@@ -54,10 +53,13 @@ use_multiple_colors = st.sidebar.checkbox("Usar múltiples colores")
|
|
| 54 |
# Seleccionar color(es) para el gráfico
|
| 55 |
if use_multiple_colors:
|
| 56 |
num_colors = len(y_values.split(","))
|
| 57 |
-
colors = [hex_to_rgba(st.sidebar.color_picker(f"Color {i+1}", predefined_colors[i % len(predefined_colors)]), alpha=0.
|
| 58 |
for i in range(num_colors)]
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
-
color = hex_to_rgba(st.sidebar.color_picker("Color del Gráfico", "#24CBA0"), alpha=0.
|
|
|
|
| 61 |
|
| 62 |
# Procesar valores
|
| 63 |
x = x_values.split(",")
|
|
@@ -95,7 +97,7 @@ else:
|
|
| 95 |
elif chart_type == "Barras":
|
| 96 |
fig = px.bar(data, x="X", y="Y", title="Gráfico de Barras", hover_name="Nombre" if names else None)
|
| 97 |
if not use_multiple_colors:
|
| 98 |
-
fig.update_traces(marker_color=color, marker_line_color=
|
| 99 |
fig.update_layout(bargap=0.2) # Ajustar el espacio entre las barras
|
| 100 |
elif chart_type == "Dispersión":
|
| 101 |
fig = px.scatter(data, x="X", y="Y", title="Gráfico de Dispersión", hover_name="Nombre" if names else None)
|
|
@@ -104,7 +106,7 @@ else:
|
|
| 104 |
elif chart_type == "Área":
|
| 105 |
fig = px.area(data, x="X", y="Y", title="Gráfico de Área", line_shape="spline", hover_name="Nombre" if names else None)
|
| 106 |
if not use_multiple_colors:
|
| 107 |
-
fig.update_traces(fillcolor=color, line_color=
|
| 108 |
elif chart_type == "Pastel":
|
| 109 |
fig = px.pie(data, values="Y", names="X", title="Gráfico de Pastel", hover_name="Nombre" if names else None)
|
| 110 |
if not use_multiple_colors:
|
|
@@ -123,7 +125,7 @@ else:
|
|
| 123 |
|
| 124 |
# Aplicar múltiples colores si se seleccionó la opción
|
| 125 |
if use_multiple_colors and chart_type != "Pastel":
|
| 126 |
-
fig.update_traces(marker_color=colors, marker_line_color=
|
| 127 |
elif use_multiple_colors and chart_type == "Pastel":
|
| 128 |
fig.update_traces(marker=dict(colors=colors))
|
| 129 |
|
|
|
|
| 23 |
# Función para convertir HEX a RGBA con transparencia
|
| 24 |
def hex_to_rgba(hex, alpha=1.0):
|
| 25 |
hex = hex.lstrip('#')
|
|
|
|
| 26 |
return f'rgba({int(hex[0:2], 16)},{int(hex[2:4], 16)},{int(hex[4:6], 16)},{alpha})'
|
| 27 |
|
| 28 |
# Colores predefinidos
|
|
|
|
| 53 |
# Seleccionar color(es) para el gráfico
|
| 54 |
if use_multiple_colors:
|
| 55 |
num_colors = len(y_values.split(","))
|
| 56 |
+
colors = [hex_to_rgba(st.sidebar.color_picker(f"Color {i+1}", predefined_colors[i % len(predefined_colors)]), alpha=0.3)
|
| 57 |
for i in range(num_colors)]
|
| 58 |
+
border_colors = [hex_to_rgba(st.sidebar.color_picker(f"Color {i+1}", predefined_colors[i % len(predefined_colors)]), alpha=0.6)
|
| 59 |
+
for i in range(num_colors)]
|
| 60 |
else:
|
| 61 |
+
color = hex_to_rgba(st.sidebar.color_picker("Color del Gráfico", "#24CBA0"), alpha=0.3)
|
| 62 |
+
border_color = hex_to_rgba(st.sidebar.color_picker("Color del Gráfico", "#24CBA0"), alpha=0.6)
|
| 63 |
|
| 64 |
# Procesar valores
|
| 65 |
x = x_values.split(",")
|
|
|
|
| 97 |
elif chart_type == "Barras":
|
| 98 |
fig = px.bar(data, x="X", y="Y", title="Gráfico de Barras", hover_name="Nombre" if names else None)
|
| 99 |
if not use_multiple_colors:
|
| 100 |
+
fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=1.5)
|
| 101 |
fig.update_layout(bargap=0.2) # Ajustar el espacio entre las barras
|
| 102 |
elif chart_type == "Dispersión":
|
| 103 |
fig = px.scatter(data, x="X", y="Y", title="Gráfico de Dispersión", hover_name="Nombre" if names else None)
|
|
|
|
| 106 |
elif chart_type == "Área":
|
| 107 |
fig = px.area(data, x="X", y="Y", title="Gráfico de Área", line_shape="spline", hover_name="Nombre" if names else None)
|
| 108 |
if not use_multiple_colors:
|
| 109 |
+
fig.update_traces(fillcolor=color, line_color=border_color)
|
| 110 |
elif chart_type == "Pastel":
|
| 111 |
fig = px.pie(data, values="Y", names="X", title="Gráfico de Pastel", hover_name="Nombre" if names else None)
|
| 112 |
if not use_multiple_colors:
|
|
|
|
| 125 |
|
| 126 |
# Aplicar múltiples colores si se seleccionó la opción
|
| 127 |
if use_multiple_colors and chart_type != "Pastel":
|
| 128 |
+
fig.update_traces(marker_color=colors, marker_line_color=border_colors, marker_line_width=1.5)
|
| 129 |
elif use_multiple_colors and chart_type == "Pastel":
|
| 130 |
fig.update_traces(marker=dict(colors=colors))
|
| 131 |
|