matplotlib的wedgeprops设置饼图牵引线的粗细不生效
可能是因为wedgeprops参数中的linewidth属性被其他参数覆盖了。可以尝试将linewidth属性放在最后一个参数中,或者使用字典方式传递wedgeprops参数,例如:
import matplotlib.pyplot as plt
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
colors = ['red', 'green', 'blue', 'yellow']
explode = (0.1, 0, 0, 0)
fig, ax = plt.subplots()
wedgeprops = {'linewidth': 2, 'edgecolor': 'white'}
ax.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90, wedgeprops=wedgeprops)
ax.axis('equal')
plt.show()
此外,还可以尝试使用set_linewidth()方法来设置线条宽度,例如:
import matplotlib.pyplot as plt
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
colors = ['red', 'green', 'blue', 'yellow']
explode = (0.1, 0, 0, 0)
fig, ax = plt.subplots()
wedges, _, _ = ax.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
for wedge in wedges:
wedge.set_linewidth(2)
ax.axis('equal')
plt.show()
以上两种方法都可以设置饼图牵引线的粗细
原文地址: http://www.cveoy.top/t/topic/htKJ 著作权归作者所有。请勿转载和采集!