matplotlib 如何避免重叠的图例和饼图[重复]

6yjfywim  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(180)

此问题已在此处有答案

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()

r7s23pms

r7s23pms1#

可以在plt.legend中使用bbox_to_anchor参数

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

相关问题