1、功能介紹:
使用 python 的 matplotlib 庫來創建一個簡單的餅圖。
2、代碼部分:
import matplotlib.pyplot as plt# 示例數據
labels = ['A', 'B', 'C', 'D', 'E'] # 類別標簽
sizes = [15, 30, 45, 5, 5] # 每個類別對應的數值(百分比)# 繪制餅圖
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, colors=['#ff9999','#66b3ff','#99ff99','#ffcc99','#c2c2f0'])# 添加標題
plt.title('Pie Chart Example')# 顯示圖形
plt.show()