Roberta2024 commited on
Commit
5b8748d
·
verified ·
1 Parent(s): 510aacc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -58,35 +58,34 @@ if st.button("生成圖表"):
58
  # 創建一個標籤頁布局
59
  tab1, tab2 = st.tabs(["圓餅圖", "長條圖"])
60
 
61
- with tab1:
62
- # 使用 plotly 創建圓餅圖
63
- fig_pie = px.pie(
64
- selected_df,
65
- names='公司名稱',
66
- values=column_choice,
67
- title=f"{dataset_choice} - {column_choice} 圓餅圖",
68
- color_discrete_sequence=px.colors.qualitative.Pastel
69
- )
70
-
71
- fig_pie.update_traces(textposition='inside', textinfo='percent+label')
72
 
73
- # 將 legend 移到圖表的下方
74
- fig_pie.update_layout(
75
- font=dict(size=12),
76
- legend=dict(
77
- orientation="h", # 橫向排列
78
- yanchor="top", # 固定在圖表的頂部
79
- y=-0.3, # 將 legend 移到圖表下方,調整這個值控制距離
80
- xanchor="center",
81
- x=0.5
82
- ),
83
- height=700, # 增加圖表高度
84
- margin=dict(t=50, b=50, l=50, r=50) # 邊距調整
85
- )
86
 
87
- st.plotly_chart(fig_pie, use_container_width=True)
88
 
89
-
90
  with tab2:
91
  # 使用 plotly 創建長條圖
92
  fig_bar = px.bar(selected_df, x='公司名稱', y=column_choice,
 
58
  # 創建一個標籤頁布局
59
  tab1, tab2 = st.tabs(["圓餅圖", "長條圖"])
60
 
61
+ with tab1:
62
+ # 使用 plotly 創建圓餅圖
63
+ fig_pie = px.pie(
64
+ selected_df,
65
+ names='公司名稱',
66
+ values=column_choice,
67
+ title=f"{dataset_choice} - {column_choice} 圓餅圖",
68
+ color_discrete_sequence=px.colors.qualitative.Pastel
69
+ )
70
+
71
+ fig_pie.update_traces(textposition='inside', textinfo='percent+label')
72
 
73
+ # 將 legend 移到圖表的下方
74
+ fig_pie.update_layout(
75
+ font=dict(size=12),
76
+ legend=dict(
77
+ orientation="h", # 橫向排列
78
+ yanchor="top", # 固定在圖表的頂部
79
+ y=-0.3, # 將 legend 移到圖表下方,調整這個值控制距離
80
+ xanchor="center",
81
+ x=0.5
82
+ ),
83
+ height=700, # 增加圖表高度
84
+ margin=dict(t=50, b=50, l=50, r=50) # 邊距調整
85
+ )
86
 
87
+ st.plotly_chart(fig_pie, use_container_width=True)
88
 
 
89
  with tab2:
90
  # 使用 plotly 創建長條圖
91
  fig_bar = px.bar(selected_df, x='公司名稱', y=column_choice,