tx3bas commited on
Commit
714173e
verified
1 Parent(s): 740f00d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import streamlit as st
2
- import altair as alt
3
  import pandas as pd
4
  import numpy as np
5
- import plotly.express as px # Importar plotly.express
6
 
7
  # Configuraci贸n de la p谩gina
8
  st.set_page_config(page_title="Generador de Gr谩ficos Personalizado", layout="wide")
@@ -146,20 +145,16 @@ else:
146
  else:
147
  fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
148
  elif chart_type == "Barras":
149
- bar_data = data.melt('X', var_name='variable', value_name='value')
150
- bar_chart = alt.Chart(bar_data).mark_bar().encode(
151
- x=alt.X('X:N' if not horizontal_bars else 'value:Q', title=x_label if not horizontal_bars else y_label),
152
- y=alt.Y('value:Q' if not horizontal_bars else 'X:N', title=y_label if not horizontal_bars else x_label),
153
- color='variable:N' if use_multiple_colors else alt.value(colors[0]),
154
- tooltip=['X:N', 'value:Q']
155
- ).properties(
156
- width=graph_width,
157
- height=graph_height,
158
- title=chart_title
159
- )
160
- if stacked_bars:
161
- bar_chart = bar_chart.encode(y=alt.Y('value:Q', stack='zero' if not horizontal_bars else None))
162
- st.altair_chart(bar_chart, use_container_width=True)
163
  elif chart_type == "Donut":
164
  figs = []
165
  for i, y_name in enumerate(y_names_list):
@@ -186,7 +181,7 @@ else:
186
  st.plotly_chart(fig)
187
 
188
  # A帽adir anotaci贸n para el t铆tulo
189
- if chart_type != "Donut" and chart_type != "Barras":
190
  fig.update_layout(
191
  title=dict(
192
  text=f"{chart_title}",
 
1
  import streamlit as st
2
+ import plotly.express as px
3
  import pandas as pd
4
  import numpy as np
 
5
 
6
  # Configuraci贸n de la p谩gina
7
  st.set_page_config(page_title="Generador de Gr谩ficos Personalizado", layout="wide")
 
145
  else:
146
  fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
147
  elif chart_type == "Barras":
148
+ if horizontal_bars:
149
+ fig = px.bar(data, x=y_names_list, y="X", orientation='h', barmode='stack' if stacked_bars else 'group')
150
+ else:
151
+ fig = px.bar(data, x="X", y=y_names_list, barmode='stack' if stacked_bars else 'group')
152
+ fig.update_traces(hovertemplate=hovertemplate)
153
+ if use_multiple_colors:
154
+ fig.update_traces(marker_color=colors[:len(x)], marker_line_color=border_colors[:len(x)], marker_line_width=border_width)
155
+ else:
156
+ fig.update_traces(marker_color=color, marker_line_color=border_color, marker_line_width=border_width)
157
+ fig.update_layout(bargap=0.2)
 
 
 
 
158
  elif chart_type == "Donut":
159
  figs = []
160
  for i, y_name in enumerate(y_names_list):
 
181
  st.plotly_chart(fig)
182
 
183
  # A帽adir anotaci贸n para el t铆tulo
184
+ if chart_type != "Donut":
185
  fig.update_layout(
186
  title=dict(
187
  text=f"{chart_title}",