Seaborn

Seaborn的donutplot()函数怎么使用

小亿
82
2024-05-15 17:22:21
栏目: 编程语言

Seaborn库中并没有内置的donutplot()函数,但是可以通过使用其他方式来绘制类似donut图。

一种方式是使用matplotlib库的pie()函数来绘制环形图,然后通过添加一个小圆圈来实现donut图的效果。下面是一个示例代码:

import matplotlib.pyplot as plt

# 创建数据
labels = ['A', 'B', 'C', 'D']
sizes = [25, 35, 20, 20]

# 创建环形图
fig, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, wedgeprops=dict(width=0.3))
ax.axis('equal')  # 保持图形为圆形

# 添加一个小圆圈
circle = plt.Circle((0, 0), 0.7, color='white')
ax.add_artist(circle)

plt.show()

通过这种方法可以绘制出类似donut图的效果。您也可以根据需要调整参数和样式来自定义图形。

0
看了该问题的人还看了