0

I am trying to draw a pie chart using python matplotlib. How to position the legend and pie chart so they are not overlapping each other. My code is as below:

import matplotlib.pyplot as plt
import numpy as np
y = np.array([1,117,11,5])
mylabels ="Complete","Pass","Fail","Block"
mycolors = ["b","g","r","c"]
myexplode =[0.6,0,0.4,0]
plt.pie(y,labels=mylabels,explode = myexplode,shadow=True,colors = mycolors,autopct 
='%1.1f%%')
plt.legend(title ="Test result types")
plt.show()

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
PChao
  • 417
  • 2
  • 5
  • 17

1 Answers1

0

You can use the bbox_to_anchor parameter in plt.legend

plt.legend(title="Test result types", bbox_to_anchor=(1, 1.15))

enter image description here

Guy
  • 46,488
  • 10
  • 44
  • 88