问题
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
回答1:
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)]
回答2:
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'
来源:https://stackoverflow.com/questions/20551477/changing-line-properties-in-matplotlib-pie-chart