Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Nested pie chart graphing function - put legend in subplot

def pie_chart_nested(labels, sizes, colors, labels_sub, sizes_sub, colors_sub, skip, end, right):
    
    plt.figure(figsize = (10,8))

    #outer donut
    wedgeprops = {'linewidth': 4, "edgecolor": "w"}
    textprops = {"fontsize":16}

    plt.pie(sizes, colors = colors, labels = labels, autopct = '%1.1f%%', 
        startangle=90, pctdistance=0.85, textprops = textprops, wedgeprops = wedgeprops)
    
    #inner donut
    plt.pie(sizes_sub, colors = colors_sub, labels = labels_sub, autopct = '%1.1f', radius=0.7, startangle=90, 
            labeldistance = None, pctdistance =0.78, wedgeprops = wedgeprops)
    
    #legend formatting
    handles, labels = plt.gca().get_legend_handles_labels()   #get handles & labels of the chart

                       #skip legend of the outer donut, #only display legend of the inner donut
    plt.legend(handles[skip:skip + end], labels[skip:skip + end], bbox_to_anchor = (1,0.5), loc = 'upper right',
               fontsize = 15, bbox_transform=plt.gcf().transFigure) 
    
    #put legend on subplot, avoid overlapping with pie chart
    plt.subplots_adjust(left=0, bottom=0.1, right=right) 
    
    centre_circle = plt.Circle((0,0),0.4,fc='white')
    plt.gcf().gca().add_artist(centre_circle)      
    
    plt.axis('equal')  
    plt.tight_layout()
    plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: iterate over batch of dict keys at once python 
Python :: Open AI Call 
Python :: run thread that inputs into queue and other threads process that python 
Python :: How to Use the abs() Function with a Complex Number Argument 
Python :: python automation to sort files 
Python :: replace python enter number of characters 
Python :: extract metadata from xml tei file python 
Python :: change between two python 3 version in raspberrry pi 
Python :: theano_flags windows 
Python :: index is datetime and i want the row number 
Python :: pyspark rdd method 
Python :: reate the "soup." This is a beautiful soup object: 
Python :: how to get foregine key field from models 
Python :: my name is raghuveer 
Python :: python get text between two comma 
Python :: why static kwyword not in python 
Python :: ordereddict move to end 
Python :: python measure volum from audio file 
Python :: difference in django project view and app view 
Python :: [E053] Could not read config.cfg from C:UsershpAppDataLocalProgramsPythonPython37libsite-packages esume_parserdegreemodelconfig.cfg 
Python :: Return the key-value pairs in this RDD to the master as a dictionary. 
Python :: Filters rows using the given condition 
Python :: How to hyperlink image in blender 
Python :: python write request must be str not bytes 
Python :: discord.py get channel name from id 
Python :: text input tkinter 
Python :: compute mean over y for same x numpy 
Python :: fonction parcourt en largeure sur un graphe 
Python :: matplotlib csv-datei anpassen und verwenden 
Python :: saree 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =