Search code examples
pythonmatplotlibpie-chart

fill matplotlib pie chart sectors with my string labels


as to_show=['A','B','C','D','E'] hello i want to fill the sectors of pie chart with some string values like A,B,C,D,E autopct is a function for this but i don't know the exact method for showing in the sectors of pie chart and hide the automatic made %ages values.


Solution

  • import matplotlib.pyplot as plt  # make the pie circular by setting the aspect ratio to 1 
    plt.figure(figsize=plt.figaspect(1)) 
    index = [1, 2, 3, 4] 
    values = [1, 2, 3, 4] 
    labels = ['a', 'b', 'c', 'd'] 
    cutom_labels = ['1', '2,3', '4,5', '6']
    
    num = -1  
     
    plt.pie(values, labels=cutom_labels,labeldistance=0.5) 
    plt.pie(values, labels=labels) 
    plt.show()`