在matplotlib中,饼图周围的空格可以通过设置图形的边界框(bbox)来删除。具体步骤如下:
import matplotlib.pyplot as plt
sizes = [15, 30, 45, 10] # 饼图各部分的大小
labels = ['A', 'B', 'C', 'D'] # 饼图各部分的标签
plt.pie(sizes, labels=labels)
plt.gca().set_aspect('equal') # 设置图形的纵横比为1,使饼图为正圆形
plt.subplots_adjust(left=0, right=1, top=1, bottom=0) # 调整子图的边界框,使饼图填满整个图像
完整代码示例:
import matplotlib.pyplot as plt
sizes = [15, 30, 45, 10]
labels = ['A', 'B', 'C', 'D']
plt.pie(sizes, labels=labels)
plt.gca().set_aspect('equal')
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
plt.show()
这样,饼图周围的空格就会被删除,使饼图填满整个图像。
推荐的腾讯云相关产品:腾讯云服务器(CVM)、腾讯云对象存储(COS)、腾讯云数据库(TencentDB)等。你可以通过访问腾讯云官方网站(https://cloud.tencent.com/)了解更多关于这些产品的详细信息。
领取专属 10元无门槛券
手把手带您无忧上云