Roberta2024 commited on
Commit
6e3d7dc
·
verified ·
1 Parent(s): 98655f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
  import streamlit as st
3
  import pandas as pd
4
  import requests
@@ -61,13 +60,15 @@ if st.button("生成圖表"):
61
 
62
  with tab1:
63
  # 使用 plotly 創建圓餅圖
64
- fig_pie = px.pie(selected_df, names=selected_df['公司名稱'], values=column_choice,
65
  title=f"{dataset_choice} - {column_choice} 圓餅圖",
66
  color_discrete_sequence=px.colors.qualitative.Pastel)
67
  fig_pie.update_traces(textposition='inside', textinfo='percent+label')
68
  fig_pie.update_layout(
69
- font=dict(size=14),
70
- legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
 
 
71
  )
72
  st.plotly_chart(fig_pie, use_container_width=True)
73
 
@@ -75,14 +76,15 @@ if st.button("生成圖表"):
75
  # 使用 plotly 創建長條圖
76
  fig_bar = px.bar(selected_df, x='公司名稱', y=column_choice,
77
  title=f"{dataset_choice} - {column_choice} 長條圖",
78
- color='公司名稱', # 為每個公司使用不同的顏色
79
  color_discrete_sequence=px.colors.qualitative.Pastel)
80
  fig_bar.update_layout(
81
  xaxis_title="企業",
82
  yaxis_title=column_choice,
83
- font=dict(size=14),
84
  xaxis_tickangle=-45,
85
- showlegend=False # 隱藏圖例,因為顏色已經用於區分不同的公司
 
86
  )
87
  st.plotly_chart(fig_bar, use_container_width=True)
88
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import requests
 
60
 
61
  with tab1:
62
  # 使用 plotly 創建圓餅圖
63
+ fig_pie = px.pie(selected_df, names='公司名稱', values=column_choice,
64
  title=f"{dataset_choice} - {column_choice} 圓餅圖",
65
  color_discrete_sequence=px.colors.qualitative.Pastel)
66
  fig_pie.update_traces(textposition='inside', textinfo='percent+label')
67
  fig_pie.update_layout(
68
+ font=dict(size=12),
69
+ legend=dict(orientation="h", yanchor="bottom", y=-0.5, xanchor="center", x=0.5),
70
+ height=700, # 增加圖表高度
71
+ margin=dict(t=100, b=100) # 增加上下邊距
72
  )
73
  st.plotly_chart(fig_pie, use_container_width=True)
74
 
 
76
  # 使用 plotly 創建長條圖
77
  fig_bar = px.bar(selected_df, x='公司名稱', y=column_choice,
78
  title=f"{dataset_choice} - {column_choice} 長條圖",
79
+ color='公司名稱',
80
  color_discrete_sequence=px.colors.qualitative.Pastel)
81
  fig_bar.update_layout(
82
  xaxis_title="企業",
83
  yaxis_title=column_choice,
84
+ font=dict(size=12),
85
  xaxis_tickangle=-45,
86
+ showlegend=False,
87
+ height=600 # 增加圖表高度
88
  )
89
  st.plotly_chart(fig_bar, use_container_width=True)
90