【问题标题】:How to set border for wedges in matplotlib pie chart?如何在 matplotlib 饼图中设置楔形的边框?
【发布时间】:2018-04-05 07:40:12
【问题描述】:

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

matplotlib 阴影边框:

【问题讨论】:

    标签: python matplotlib charts


    【解决方案1】:

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

    wedgeprops={"edgecolor":"k",'linewidth': 5, 'linestyle': 'dashed', 'antialiased': True})
    

    【讨论】:

    • 就是这样!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多