简体   繁体   中英

Spacing between the labels on pie plot matplotlib

When I plot the pie chart, 'labels' are overlapping. I do understand that this is happening due to values being equal. Is there a way to increase the spacing between labels along the perimeter of the pie chart. I do not mind the last value label moving into the first pie value area. The other solutions I saw on SO include plotting labels separately as a table but I would like it in the default format. Thanking you in anticipation.

import pandas as pd
import matplotlib.pyplot as plt

df99 = pd.DataFrame({
    'Data': ['A', 'B', 'C','D','E'],
    'Perc': [0.62, 0.31, 0.02,0.02,0.02]})
plt.pie(df99['Perc']*100, colors=['#002c4b','#392e2c','#92847a','#ccc2bb','#6b879d','#7FBAA4','#8E654C','#006CB8','#CBBBE9','#9778D3'],counterclock=False,startangle=-270,pctdistance=1.2,labeldistance=1.2,labels=df99['Data'],
        autopct=None)
plt.show()

You can rotate the labels with the rotatelabels parameter for a cleaner look.

Also, if you have many different labels, consider using a legend.

Edit: You can merely decrease the font size of labels to increase spacing, or increase the size of the figure.

fig = pyplot.figure(figsize=(#, #))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM