新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

Seaborn的donutplot()函数如何使用

发布时间:2024-05-15 17:22:21

Seaborn的donutplot()函数如何使用

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