Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def plot_grouped_barchart(): | |
| months=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] # 月份 | |
| y=np.arange(len(months)) # 數值型索引 | |
| x1=[12000, 15000, 17000, 13000, 19000, 21000] # 銷售一課 | |
| x2=[11000, 14000, 16000, 12000, 18000, 20000] # 銷售二課 | |
| height=0.35 # 長條寬度 | |
| # 繪製長條圖 | |
| plt.figure(figsize=(8, 5)) | |
| plt.barh(y - height/2, x1, height, label='Sales Team 1', color='cyan') | |
| plt.barh(y + height/2, x2, height, label='Sales Team 2', color='orange') # 設定標籤與標題 | |
| plt.ylabel('Months') | |
| plt.xlabel('Sales (in ten thousand)') | |
| plt.title('Monthly Sales Performance (Grouped)') | |
| plt.yticks(y, months) # 設定 y 軸刻度標籤 | |
| plt.legend() # 顯示圖例 | |
| plt.tight_layout() # 自動調整布局 | |
| return plt.gcf() # 返回圖表對象 | |
| iface=gr.Interface( | |
| fn=plot_grouped_barchart, | |
| inputs=[], | |
| outputs=gr.Plot(), | |
| title='Grouped Bar Chart Test(Horizontal)', | |
| flagging_mode='never' | |
| ) | |
| iface.launch() | |