在 Matplotlib 中设置饼图的牵引线粗细,可以使用参数'linewidths'。例如,如果要将牵引线的粗细设置为 2 像素,则可以使用以下代码:

import matplotlib.pyplot as plt

labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]

fig, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, counterclock=False, 
       wedgeprops={'linewidth': 2, 'edgecolor': 'white'}, textprops={'fontsize': 14})

plt.show()

在上面的代码中,我们通过'wedgeprops' 参数设置牵引线的粗细为 2 像素,并将其边缘颜色设置为白色。通过这种方式,我们可以轻松地调整饼图中的牵引线粗细和颜色,以满足我们的需求。

Matplotlib 饼图牵引线粗细设置教程

原文地址: https://www.cveoy.top/t/topic/oWvZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录