Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import plotly.express as px
|
| 3 |
-
import plotly.graph_objects as go
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
|
|
@@ -35,7 +34,7 @@ predefined_colors = [
|
|
| 35 |
st.sidebar.header("Configuración del Gráfico")
|
| 36 |
|
| 37 |
# Tipo de gráfico
|
| 38 |
-
chart_type = st.sidebar.selectbox("Tipo de Gráfico", ["Línea", "Barras", "Dispersión", "Área", "Pastel"
|
| 39 |
|
| 40 |
# Ingresar valores para los ejes
|
| 41 |
x_values = st.sidebar.text_area("Valores para X (separados por comas)", "2013,2014,2015,2016,2017,2018")
|
|
@@ -116,45 +115,12 @@ else:
|
|
| 116 |
fig = px.pie(data, values="Y", names="X", title="Gráfico de Pastel", hover_name="Nombre" if names else None)
|
| 117 |
if not use_multiple_colors:
|
| 118 |
fig.update_traces(marker=dict(colors=[color]*len(x)))
|
| 119 |
-
elif chart_type == "Doughnut":
|
| 120 |
-
fig = px.pie(data, values="Y", names="X", title="Doughnut Chart", hole=0.4, hover_name="Nombre" if names else None)
|
| 121 |
-
if not use_multiple_colors:
|
| 122 |
-
fig.update_traces(marker=dict(colors=[color]*len(x)))
|
| 123 |
-
elif chart_type == "Scatter":
|
| 124 |
-
fig = px.scatter(data, x="X", y="Y", title="Scatter Plot", hover_name="Nombre" if names else None)
|
| 125 |
-
if not use_multiple_colors:
|
| 126 |
-
fig.update_traces(marker_color=color)
|
| 127 |
-
elif chart_type == "Bar Horizontal":
|
| 128 |
-
fig = px.bar(data, x="Y", y="X", title="Bar Chart Horizontal", orientation='h', hover_name="Nombre" if names else None)
|
| 129 |
-
if not use_multiple_colors:
|
| 130 |
-
fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=1.5)
|
| 131 |
-
fig.update_layout(bargap=0.2) # Ajustar el espacio entre las barras
|
| 132 |
-
elif chart_type == "Radar":
|
| 133 |
-
fig = go.Figure()
|
| 134 |
-
fig.add_trace(go.Scatterpolar(
|
| 135 |
-
r=y,
|
| 136 |
-
theta=x,
|
| 137 |
-
fill='toself',
|
| 138 |
-
name='Radar Chart',
|
| 139 |
-
line=dict(color=color)
|
| 140 |
-
))
|
| 141 |
-
fig.update_layout(
|
| 142 |
-
polar=dict(
|
| 143 |
-
radialaxis=dict(visible=True, range=[y_min, y_max])
|
| 144 |
-
),
|
| 145 |
-
showlegend=False
|
| 146 |
-
)
|
| 147 |
-
elif chart_type == "Time Line":
|
| 148 |
-
data['X'] = pd.to_datetime(data['X'], format='%Y') # Ajustar el formato de fecha según tus datos
|
| 149 |
-
fig = px.line(data, x='X', y='Y', title='Time Line', hover_name="Nombre" if names else None)
|
| 150 |
-
if not use_multiple_colors:
|
| 151 |
-
fig.update_traces(line_color=color)
|
| 152 |
|
| 153 |
# Aplicar configuración común
|
| 154 |
fig.update_layout(**common_layout)
|
| 155 |
|
| 156 |
# Configuraciones específicas para gráficos no circulares
|
| 157 |
-
if chart_type
|
| 158 |
fig.update_layout(
|
| 159 |
xaxis=dict(categoryorder="category ascending"),
|
| 160 |
yaxis=dict(range=[y_min, y_max], zeroline=True)
|
|
@@ -162,18 +128,14 @@ else:
|
|
| 162 |
fig.update_yaxes(nticks=20)
|
| 163 |
|
| 164 |
# Aplicar múltiples colores si se seleccionó la opción
|
| 165 |
-
if use_multiple_colors:
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
fig.update_traces(marker=dict(colors=colors))
|
| 170 |
-
elif chart_type == "Radar":
|
| 171 |
-
for i, trace in enumerate(fig.data):
|
| 172 |
-
trace.update(line=dict(color=colors[i]))
|
| 173 |
|
| 174 |
# Mostrar el gráfico
|
| 175 |
st.plotly_chart(fig)
|
| 176 |
|
| 177 |
# Información adicional
|
| 178 |
st.write("""
|
| 179 |
-
""")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import plotly.express as px
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
|
|
|
|
| 34 |
st.sidebar.header("Configuración del Gráfico")
|
| 35 |
|
| 36 |
# Tipo de gráfico
|
| 37 |
+
chart_type = st.sidebar.selectbox("Tipo de Gráfico", ["Línea", "Barras", "Dispersión", "Área", "Pastel"])
|
| 38 |
|
| 39 |
# Ingresar valores para los ejes
|
| 40 |
x_values = st.sidebar.text_area("Valores para X (separados por comas)", "2013,2014,2015,2016,2017,2018")
|
|
|
|
| 115 |
fig = px.pie(data, values="Y", names="X", title="Gráfico de Pastel", hover_name="Nombre" if names else None)
|
| 116 |
if not use_multiple_colors:
|
| 117 |
fig.update_traces(marker=dict(colors=[color]*len(x)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
# Aplicar configuración común
|
| 120 |
fig.update_layout(**common_layout)
|
| 121 |
|
| 122 |
# Configuraciones específicas para gráficos no circulares
|
| 123 |
+
if chart_type != "Pastel":
|
| 124 |
fig.update_layout(
|
| 125 |
xaxis=dict(categoryorder="category ascending"),
|
| 126 |
yaxis=dict(range=[y_min, y_max], zeroline=True)
|
|
|
|
| 128 |
fig.update_yaxes(nticks=20)
|
| 129 |
|
| 130 |
# Aplicar múltiples colores si se seleccionó la opción
|
| 131 |
+
if use_multiple_colors and chart_type != "Pastel":
|
| 132 |
+
fig.update_traces(marker_color=colors, marker_line_color=border_colors, marker_line_width=1.5)
|
| 133 |
+
elif use_multiple_colors and chart_type == "Pastel":
|
| 134 |
+
fig.update_traces(marker=dict(colors=colors))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
# Mostrar el gráfico
|
| 137 |
st.plotly_chart(fig)
|
| 138 |
|
| 139 |
# Información adicional
|
| 140 |
st.write("""
|
| 141 |
+
""")
|