您的位置:宽带测速网 > 编程知识 > Seaborn的donutplot()函数怎么使用

Seaborn的donutplot()函数怎么使用

2025-07-04 09:26来源:互联网 [ ]

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图的效果。您也可以根据需要调整参数和样式来自定义图形。