Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,6 +40,66 @@ for i in range(num_y_vars):
|
|
| 40 |
# Opción para apilar franjas de tiempo
|
| 41 |
stacked = st.sidebar.checkbox("Apilar Franjas de Tiempo", value=True)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Crear el DataFrame con franjas de tiempo
|
| 44 |
data_list = []
|
| 45 |
for y_name, (start_date, end_date) in y_values.items():
|
|
|
|
| 40 |
# Opción para apilar franjas de tiempo
|
| 41 |
stacked = st.sidebar.checkbox("Apilar Franjas de Tiempo", value=True)
|
| 42 |
|
| 43 |
+
# Crear el DataFrame con franjas de tiempo
|
| 44 |
+
data_list = []
|
| 45 |
+
for y_name, (start_date, end_date) in y_values.items():
|
| 46 |
+
data_list.append({
|
| 47 |
+
'Variable': y_name,
|
| 48 |
+
'Start': datetime.strptime(start_date, '%Y-%m-%d'),
|
| 49 |
+
'End': datetime.strptime(end_date, '%Y-%m-%d'),
|
| 50 |
+
'Category': 'Apilado' if stacked else y_name # Esto asegura que se apilen en la misma fila pero mantengan su color
|
| 51 |
+
})
|
| 52 |
+
|
| 53 |
+
data = pd.DataFrame(data_list)
|
| 54 |
+
|
| 55 |
+
# Ajustar fechas para simular apilamiento si está activado
|
| 56 |
+
if stacked:
|
| 57 |
+
offset = timedelta(days=1) # Ajusta el offset según sea necesario
|
| 58 |
+
for i in range(1, len(data)):
|
| 59 |
+
data.loc[i, 'Start'] = data.loc[i-1, 'End']
|
| 60 |
+
data.loc[i, 'End'] = data.loc[i, 'Start'] + (data.loc[i, 'End'] - data.loc[i, 'Start'])
|
| 61 |
+
|
| 62 |
+
# Crear gráfico de franjas de tiempo
|
| 63 |
+
fig = px.timeline(data, x_start="Start", x_end="End", y="Category", color="Variable", title=chart_title)
|
| 64 |
+
|
| 65 |
+
# Actualizar el diseño del gráfico
|
| 66 |
+
fig.update_yaxes(categoryorder="total ascending")
|
| 67 |
+
|
| 68 |
+
# Personalizar el formato de tiempo en el eje X
|
| 69 |
+
if time_format == "Año":
|
| 70 |
+
tickformat = "%Y"
|
| 71 |
+
else:
|
| 72 |
+
tickformat = "%Y-%m-%d" # Ajusta según el formato deseado
|
| 73 |
+
|
| 74 |
+
fig.update_layout(
|
| 75 |
+
xaxis_title="Tiempo",
|
| 76 |
+
yaxis_title="Variables",
|
| 77 |
+
xaxis=dict(
|
| 78 |
+
tickformat=tickformat,
|
| 79 |
+
titlefont=dict(size=14),
|
| 80 |
+
tickfont=dict(size=12),
|
| 81 |
+
),
|
| 82 |
+
yaxis=dict(
|
| 83 |
+
titlefont=dict(size=14),
|
| 84 |
+
tickfont=dict(size=12),
|
| 85 |
+
),
|
| 86 |
+
width=800,
|
| 87 |
+
height=600,
|
| 88 |
+
margin=dict(l=60, r=40, t=100, b=40),
|
| 89 |
+
font=dict(family="Times New Roman", size=18, color="black")
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# Mostrar el gráfico
|
| 93 |
+
st.plotly_chart(fig)
|
| 94 |
+
|
| 95 |
+
# Información adicional
|
| 96 |
+
st.write("Aquí puede añadir información adicional sobre los gráficos generados.")
|
| 97 |
+
if y_start and y_end and y_name:
|
| 98 |
+
y_values[y_name] = (y_start, y_end)
|
| 99 |
+
|
| 100 |
+
# Opción para apilar franjas de tiempo
|
| 101 |
+
stacked = st.sidebar.checkbox("Apilar Franjas de Tiempo", value=True)
|
| 102 |
+
|
| 103 |
# Crear el DataFrame con franjas de tiempo
|
| 104 |
data_list = []
|
| 105 |
for y_name, (start_date, end_date) in y_values.items():
|