Update app.py
Browse files
app.py
CHANGED
|
@@ -70,17 +70,17 @@ with st.sidebar.expander("Opciones Adicionales"):
|
|
| 70 |
hole_size = st.slider("Tamaño del agujero (%)", min_value=0, max_value=100, value=30, step=1) / 100
|
| 71 |
|
| 72 |
# Opción para múltiples colores (siempre activada para Donut)
|
| 73 |
-
use_multiple_colors = st.sidebar.checkbox("Usar múltiples colores", value=True, key="use_multiple_colors")
|
| 74 |
|
| 75 |
# Seleccionar color(es) para el gráfico
|
| 76 |
selected_color = st.sidebar.color_picker("Color", "#24CBA0", key="single_color")
|
| 77 |
|
| 78 |
# Definir colores
|
| 79 |
-
if use_multiple_colors:
|
| 80 |
-
num_colors = len(
|
| 81 |
-
colors = [hex_to_rgba(st.sidebar.color_picker(f"Color {i+1}", predefined_colors[i % len(predefined_colors)], key=f"color_{i}"), alpha=opacity)
|
| 82 |
for i in range(num_colors)]
|
| 83 |
-
border_colors = [hex_to_rgba(
|
| 84 |
for i in range(num_colors)]
|
| 85 |
else:
|
| 86 |
color = hex_to_rgba(selected_color, alpha=opacity)
|
|
@@ -145,15 +145,18 @@ else:
|
|
| 145 |
fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
|
| 146 |
elif chart_type == "Barras":
|
| 147 |
if horizontal_bars:
|
| 148 |
-
fig = px.bar(data, x=y_names_list, y="X", orientation='h', barmode='stack' if stacked_bars else 'group')
|
| 149 |
else:
|
| 150 |
fig = px.bar(data, x="X", y=y_names_list, barmode='stack' if stacked_bars else 'group')
|
| 151 |
fig.update_traces(hovertemplate=hovertemplate)
|
| 152 |
if use_multiple_colors:
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
trace
|
|
|
|
|
|
|
|
|
|
| 157 |
else:
|
| 158 |
fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
|
| 159 |
fig.update_layout(bargap=0.2)
|
|
@@ -215,4 +218,4 @@ else:
|
|
| 215 |
fig.update_layout(xaxis_autorange=True, yaxis_autorange=True)
|
| 216 |
|
| 217 |
# Información adicional
|
| 218 |
-
st.write("Aquí puede añadir información adicional sobre los gráficos generados.")
|
|
|
|
| 70 |
hole_size = st.slider("Tamaño del agujero (%)", min_value=0, max_value=100, value=30, step=1) / 100
|
| 71 |
|
| 72 |
# Opción para múltiples colores (siempre activada para Donut)
|
| 73 |
+
use_multiple_colors = st.sidebar.checkbox("Usar múltiples colores", value=True if chart_type == "Donut" or num_y_vars > 1 else False, key="use_multiple_colors")
|
| 74 |
|
| 75 |
# Seleccionar color(es) para el gráfico
|
| 76 |
selected_color = st.sidebar.color_picker("Color", "#24CBA0", key="single_color")
|
| 77 |
|
| 78 |
# Definir colores
|
| 79 |
+
if use_multiple_colors or chart_type == "Donut":
|
| 80 |
+
num_colors = max(len(y_values_list), len(x))
|
| 81 |
+
colors = [hex_to_rgba(selected_color if i == 0 else st.sidebar.color_picker(f"Color {i+1}", predefined_colors[i % len(predefined_colors)], key=f"color_{i}"), alpha=opacity)
|
| 82 |
for i in range(num_colors)]
|
| 83 |
+
border_colors = [hex_to_rgba(selected_color if i == 0 else predefined_colors[i % len(predefined_colors)], alpha=border_opacity)
|
| 84 |
for i in range(num_colors)]
|
| 85 |
else:
|
| 86 |
color = hex_to_rgba(selected_color, alpha=opacity)
|
|
|
|
| 145 |
fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
|
| 146 |
elif chart_type == "Barras":
|
| 147 |
if horizontal_bars:
|
| 148 |
+
fig = px.bar(data, x=y_names_list[0], y="X", orientation='h', barmode='stack' if stacked_bars else 'group')
|
| 149 |
else:
|
| 150 |
fig = px.bar(data, x="X", y=y_names_list, barmode='stack' if stacked_bars else 'group')
|
| 151 |
fig.update_traces(hovertemplate=hovertemplate)
|
| 152 |
if use_multiple_colors:
|
| 153 |
+
if len(y_names_list) == 1: # Solo una variable Y
|
| 154 |
+
fig.update_traces(marker_color=colors[:len(x)], marker_line_color=border_colors[:len(x)], marker_line_width=border_width)
|
| 155 |
+
else:
|
| 156 |
+
for i, trace in enumerate(fig.data):
|
| 157 |
+
trace.marker.color = colors[i % len(colors)]
|
| 158 |
+
trace.marker.line.color = border_colors[i % len(border_colors)]
|
| 159 |
+
trace.marker.line.width = border_width
|
| 160 |
else:
|
| 161 |
fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
|
| 162 |
fig.update_layout(bargap=0.2)
|
|
|
|
| 218 |
fig.update_layout(xaxis_autorange=True, yaxis_autorange=True)
|
| 219 |
|
| 220 |
# Información adicional
|
| 221 |
+
st.write("Aquí puede añadir información adicional sobre los gráficos generados.")
|