0

I plotted a pie chart with matplotib. I want to show the labels and the percentages. I know how to change the position with pctdistance and labeldistance. Is there another way to move the text along the horizontal and vertical axes? Sometimes both labels are overlapping, espescially when I plotted nested pie charts.

import pandas as pd
import matplotlib.pyplot as plt
data = { 'T1': [1,1,1,1,1,2,2,2,2,2, 1,1,1,1,1, 2,2,2,2,2, 1,1,1,1,1, 2,2,2,2],
         'T2':['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
               'B','B', 'B', 'B', 'B', 'B',
               'C', 'C', 'C', 'C','C', 'C', 'C',
              'D', 'D', 'D', 'D']}
df = pd.DataFrame(data)
df['T1']=df['T1'].astype(str)
fig, ax=plt.subplots()
values2=df['T2'].value_counts().sort_index()


p1, t1, a1=ax.pie(values2, radius=1.3, autopct='%1.1f%%', labeldistance=0.4,   
       labels=['one', 'two', 'three', 'four'], startangle=223.5, wedgeprops=dict(width=1, edgecolor='w'));

example pie chart

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Kajette
  • 47
  • 4

0 Answers0