10

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:

enter image description 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

Community
  • 1
  • 1
Alex S
  • 4,726
  • 7
  • 39
  • 67

2 Answers2

17

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

pie

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)]
behzad.nouri
  • 74,723
  • 18
  • 126
  • 124
6

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'
Manuel G
  • 1,523
  • 1
  • 21
  • 34