此问题已在此处有答案:
How to put the legend outside the plot(18回答)
昨天关门了。
我正在尝试使用python matplotlib
绘制一个饼图。如何定位图例和饼图,使它们不相互重叠。我的代码如下:
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()
1条答案
按热度按时间r7s23pms1#
可以在
plt.legend
中使用bbox_to_anchor
参数