用Python画环形进度条
时间: 2024-10-10 15:04:10 浏览: 56
在Python中,你可以使用第三方库`matplotlib`和`patch`模块来创建环形进度条,也称为饼图。下面是一个简单的例子:
```python
import matplotlib.pyplot as plt
import numpy as np
# 设置环形进度条的参数
total = 100
completed = 60
width = 0.5
outer_radius = 0.4
inner_radius = outer_radius - width
# 创建数据
angles = np.linspace(0, 2*np.pi, total+1)
bar_values = np.zeros(total+1)
bar_values[range(completed)] = completed
# 创建环形进度条
fig, ax = plt.subplots()
ax.add_patch(plt.Patch(
annulus=annular sector=AnnularSector(
angles start=angles[:-1], end=angles[1:], inner_radius=inner_radius,
outer_radius=outer_radius, angle=360, facecolor='skyblue',
edgecolor='white', linewidth=1.2),
color='white'))
# 添加标签和标题
ax.set_title('环形进度条')
ax.set_aspect('equal') # 保持正方形比例
plt.show()
阅读全文