hussain2010 commited on
Commit
11b50ae
·
verified ·
1 Parent(s): 3912295

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -220,18 +220,29 @@ with st.sidebar.expander("Executive Dashboard Settings"):
220
  key="dashboard_layout")
221
 
222
  # Legend Position (common for all charts)
223
- legend_position_options = ["top right", "top midle", "top left",
224
- "mid right", "mid midle", "mid left",
225
- "bottom right", "bottom midle", "bottom left"]
226
  legend_position = st.sidebar.selectbox("Legend Position", legend_position_options, key="legend_position")
227
 
228
  # Map legend positions to matplotlib
229
  legend_loc_map = {
230
- "top right": "upper right", "top midle": "upper center", "top left": "upper left",
231
- "mid right": "center right", "mid midle": "center", "mid left": "center left",
232
- "bottom right": "lower right", "bottom midle": "lower center", "bottom left": "lower left"
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
235
  # Brochure and Presentation Export Options
236
  with st.sidebar.expander("Export Options"):
237
  export_format = st.selectbox("Export Format", ["PNG", "PDF", "SVG", "HTML"], key="export_format")
 
220
  key="dashboard_layout")
221
 
222
  # Legend Position (common for all charts)
223
+ legend_position_options = ["top right", "top middle", "top left",
224
+ "mid right", "mid middle", "mid left",
225
+ "bottom right", "bottom middle", "bottom left"]
226
  legend_position = st.sidebar.selectbox("Legend Position", legend_position_options, key="legend_position")
227
 
228
  # Map legend positions to matplotlib
229
  legend_loc_map = {
230
+ "top right": "upper right", "top middle": "upper center", "top left": "upper left",
231
+ "mid right": "center right", "mid middle": "center", "mid left": "center left",
232
+ "bottom right": "lower right", "bottom middle": "lower center", "bottom left": "lower left"
233
  }
234
 
235
+ # Custom bbox_to_anchor values to slightly adjust the legend position
236
+ legend_bbox_map = {
237
+ "top right": (0.9, 1.1), "top middle": (0.5, 1.1), "top left": (0.1, 1.1), # Shifted higher
238
+ "mid right": (1.1, 0.5), "mid middle": (0.5, 0.6), "mid left": (-0.1, 0.5), # Adjusted for clarity
239
+ "bottom right": (0.9, -0.1), "bottom middle": (0.5, -0.1), "bottom left": (0.1, -0.1) # Shifted lower
240
+ }
241
+
242
+ # Set the legend with both loc and bbox_to_anchor to avoid overlap
243
+ ax.legend(loc=legend_loc_map[legend_position], bbox_to_anchor=legend_bbox_map[legend_position])
244
+
245
+
246
  # Brochure and Presentation Export Options
247
  with st.sidebar.expander("Export Options"):
248
  export_format = st.selectbox("Export Format", ["PNG", "PDF", "SVG", "HTML"], key="export_format")