如何在matplotlib饼图中设置楔形的边框?

D. *_*ras 2 python charts matplotlib

在matplotlib中绘制饼图时遇到了一些问题。目前,它可以正确地绘制图表本身,但是其楔形存在一个小问题。当我在参数(例如,线宽,与线型相同)中设置了楔形道具时,它将更改图表下方的阴影,而不是楔形本身。

如何为楔形而不是阴影绘制适当的边界?这就是现在的样子。

import matplotlib.pyplot as plt

pie_chart_labels = ('Failed', 'Passed', 'Disabled')
pie_chart_colors = ('red', 'green', 'grey')
pie_chart_exploded = (0, 0.08, 0)
pie_chart_fig, pie_chart_ax = plt.subplots()
pie_chart_ax.margins(0.05)
pie_chart_ax.axis('equal')
pie_chart_test_results = (8, 5, 2)

pie_chart_ax.pie(pie_chart_test_results, 
                 explode=pie_chart_exploded, 
                 labels=pie_chart_labels,     
                 colors=pie_chart_colors, 
                 shadow=True, 
                 counterclock=False, 
                 startangle=90, 
                 wedgeprops={'linewidth': 1, 'linestyle': 'solid', 'antialiased': True})

pie_chart_fig.savefig('PieChart.png')
Run Code Online (Sandbox Code Playgroud)

matplotlib边框的阴影:

在此处输入图片说明

Imp*_*est 5

关键是您的楔形当前没有任何可以配置的边线。如果给它们一个边缘,还可以给它一些属性。

wedgeprops={"edgecolor":"k",'linewidth': 5, 'linestyle': 'dashed', 'antialiased': True})
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明