I'm trying to make the lines on my matplotlib pie chart much lighter. Because I have so many slices, the lines are way too thick, as shown here:
I read this example which suggests using rcparam like this:
matplotlib.rcParams['text.color'] = 'r'
matplotlib.rcParams['lines.linewidth'] = 2
but although I can change the text color, it doesn't change the width of the lines between the pie slices. I believe that's because the slices aren't governed by line objects but by wedge objects. So is there a way to set the wedge border style and color?
Thanks a lot, Alex
Matplotlib pie chart legend font size To change the fontsize we use the fontsize argument with the legend() method.
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 '%.
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.
try this:
ax = plt.subplot(111)
wedges, texts = ax.pie(np.abs(np.random.randn(5)))
for w in wedges:
w.set_linewidth(2)
w.set_edgecolor('cyan')
Additionally, if you only have an axes
object and don't have direct access to the pie's wedges you can retrieve the wedges from ax.patches
:
wedges = [patch for patch in ax.patches if isinstance(patch, matplotlib.patches.Wedge)]
Im coming late to this party, but just found that, for pie charts, instead of using:
plt.rcParams['lines.linewidth'] = 2
you can use:
plt.rcParams['patch.linewidth'] = 0
Also, to change the pie chart line color use this:
plt.rcParams['patch.edgecolor'] = 'white'
instead of:
plt.rcParams['line.color'] = 'white'
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