Got some problem with plotting a pie chart in matplotlib. Currently it's plotting properly the chart itself, but there is a small issue with its wedges. As I set wedgeprops in arguments (eg. linewidth, same with linestyle) it change this for shadow that is beneath chart, not for wedges itself.
How to draw proper borders for wedges and not for shadows? This is how it looks like now.
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 border for shadow:
A pie chart is a circular chart divided into wedge-like sectors, illustrating proportion. Each wedge represents a proportionate part of the whole, and the total value of the pie is always 100 percent. Pie charts can make the size of portions easy to understand at a glance.
To “explode” a pie chart means to make one of the wedges of the pie chart to stand out. To make this possible in matplotlib , we use the explode() parameter.
autopct enables you to display the percent value using Python string formatting. For example, if autopct='%. 2f' , then for each pie wedge, the format string is '%. 2f' and the numerical percent value for that wedge is pct , so the wedge label is set to the string '%. 2f'%pct .
The point is that your wedges currently do not have any edgeline which could be configured. If you give them an edge, you can also give it some properties.
wedgeprops={"edgecolor":"k",'linewidth': 5, 'linestyle': 'dashed', 'antialiased': True})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With