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

时间:2017-10-24 13:20:38

标签: python matplotlib charts

在matplotlib中绘制饼图时出现问题。目前,它正确地绘制了图表本身,但是它的楔子存在一个小问题。当我在参数中设置wedgeprops(例如线宽,与linestyle相同)时,它会更改为图表下方的阴影,而不是楔形本身。

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

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')

阴影的matplotlib边框:

enter image description here

1 个答案:

答案 0 :(得分:1)

关键是您的楔子当前没有可配置的任何边缘线。如果你给他们一个优势,你也可以给它一些属性。

argparse

enter image description here