Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import plotly.
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
|
|
@@ -11,12 +11,6 @@ def hex_to_rgba(hex_color, alpha=1.0):
|
|
| 11 |
hex_color = hex_color.lstrip('#')
|
| 12 |
return f'rgba({int(hex_color[0:2], 16)},{int(hex_color[2:4], 16)},{int(hex_color[4:6], 16)},{alpha})'
|
| 13 |
|
| 14 |
-
# Lista de fuentes más utilizadas
|
| 15 |
-
font_options = [
|
| 16 |
-
"Times New Roman", "Arial", "Helvetica", "Calibri", "Verdana",
|
| 17 |
-
"Tahoma", "Georgia", "Garamond", "Courier New", "Brush Script MT"
|
| 18 |
-
]
|
| 19 |
-
|
| 20 |
# Sidebar para la configuración del gráfico
|
| 21 |
st.sidebar.header("Configuración del Gráfico")
|
| 22 |
|
|
@@ -51,27 +45,36 @@ for y_name, (start_date, end_date) in y_values.items():
|
|
| 51 |
|
| 52 |
data = pd.DataFrame(data_list)
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Actualizar el diseño del gráfico
|
| 64 |
-
fig.update_yaxes(categoryorder="total ascending")
|
| 65 |
-
|
| 66 |
-
# Personalizar el formato de tiempo en el eje X
|
| 67 |
-
if time_format == "Año":
|
| 68 |
-
tickformat = "%Y"
|
| 69 |
-
|
| 70 |
fig.update_layout(
|
|
|
|
| 71 |
xaxis_title="Tiempo",
|
| 72 |
yaxis_title="Variables",
|
|
|
|
| 73 |
xaxis=dict(
|
| 74 |
-
tickformat=
|
| 75 |
titlefont=dict(size=14),
|
| 76 |
tickfont=dict(size=12),
|
| 77 |
),
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import plotly.graph_objects as go
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
|
|
|
|
| 11 |
hex_color = hex_color.lstrip('#')
|
| 12 |
return f'rgba({int(hex_color[0:2], 16)},{int(hex_color[2:4], 16)},{int(hex_color[4:6], 16)},{alpha})'
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Sidebar para la configuración del gráfico
|
| 15 |
st.sidebar.header("Configuración del Gráfico")
|
| 16 |
|
|
|
|
| 45 |
|
| 46 |
data = pd.DataFrame(data_list)
|
| 47 |
|
| 48 |
+
# Crear gráfico de franjas de tiempo usando plotly.graph_objects
|
| 49 |
+
fig = go.Figure()
|
| 50 |
+
|
| 51 |
+
# Agregar cada serie de tiempo al gráfico
|
| 52 |
+
colors = px.colors.qualitative.Plotly # Puedes elegir otros esquemas de color
|
| 53 |
+
|
| 54 |
+
for i, (y_name, (start_date, end_date)) in enumerate(y_values.items()):
|
| 55 |
+
start_date = pd.to_datetime(start_date)
|
| 56 |
+
end_date = pd.to_datetime(end_date)
|
| 57 |
+
|
| 58 |
+
fig.add_trace(go.Bar(
|
| 59 |
+
y=[y_name],
|
| 60 |
+
x=[(end_date - start_date).days],
|
| 61 |
+
base=start_date,
|
| 62 |
+
orientation='h',
|
| 63 |
+
name=y_name,
|
| 64 |
+
marker_color=colors[i % len(colors)],
|
| 65 |
+
text=f'{y_name}: {start_date.date()} - {end_date.date()}',
|
| 66 |
+
textposition='inside',
|
| 67 |
+
width=0.5
|
| 68 |
+
))
|
| 69 |
|
| 70 |
# Actualizar el diseño del gráfico
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
fig.update_layout(
|
| 72 |
+
title=chart_title,
|
| 73 |
xaxis_title="Tiempo",
|
| 74 |
yaxis_title="Variables",
|
| 75 |
+
barmode='stack' if stacked else 'group',
|
| 76 |
xaxis=dict(
|
| 77 |
+
tickformat="%Y-%m-%d" if time_format != "Año" else "%Y",
|
| 78 |
titlefont=dict(size=14),
|
| 79 |
tickfont=dict(size=12),
|
| 80 |
),
|