matplotlib 饼图用主图的实际标题替换最后一个饼图子图标题

matplotlib pie chart replacing last pie subplot title with actual title of the main plot

我一直 运行 遇到一个问题,其中 matplotlib pie 将我最后的子图文本值替换为实际的图标题。谁能告诉我为什么我会遇到这个问题以及如何克服它?

keep_list_tt = [6.012, 2.734, 2.76, 4.585, 4.19]
eppm_plot    = [0, 771, 830, 919, 1097]
all_test_tt = [31.344, 31.344, 31.344, 31.344, 31.344]
always_failing_list_tt = [0.112, 0.112, 0.112, 0.112, 0.112]
always_failing_list_tt = [23.203, 23.203, 23.203, 23.203, 23.203]

import matplotlib.pyplot as plt

fig, axs = plt.subplots(1,len(keep_list_tt), figsize=(30,8))
labels = ["always_failing_list_tt", "always_passing_list_tt", "keep_list_tt","remove_list_tt"]
explode = (0.2, 0,0.1,0.1)
for i in range(len(keep_list_tt)):
    eppm_pie_plot = [always_failing_list_tt[i],always_passing_list_tt[i],keep_list_tt[i],round(np.subtract(all_test_tt[i],np.add(keep_list_tt[i],np.add(always_failing_list_tt[i],always_passing_list_tt[i]))),3)] 
    pie = axs[i].pie(eppm_pie_plot, explode=explode,autopct="")
    axs[i].set_title("EPPM is - {}".format(eppm_plot[i]))
    for j, a in enumerate(pie[2]):
        a.set_text("{}".format(eppm_pie_plot[j]))
    

plt.legend(labels,bbox_to_anchor=(1.1,0.5) )
plt.axis('equal')
plt.title ("Temp")
plt.show()

问题似乎是由于 plt.axis('equal') 仅应用于循环过程之外的最后一个图形引起的。请将该代码移到循环内。当你在做的时候,优化图表的循环方式。

import matplotlib.pyplot as plt

fig, axs = plt.subplots(1,len(keep_list_tt), figsize=(30,8))
labels = ["always_failing_list_tt", "always_passing_list_tt", "keep_list_tt","remove_list_tt"]
explode = (0.2, 0,0.1,0.1)

for i, ax in enumerate(fig.axes):
    eppm_pie_plot = [always_failing_list_tt[i],always_passing_list_tt[i],keep_list_tt[i],round(np.subtract(all_test_tt[i],np.add(keep_list_tt[i],np.add(always_failing_list_tt[i],always_passing_list_tt[i]))),3)] 
    pie = ax.pie(eppm_pie_plot, explode=explode, autopct="")
    ax.set_title("EPPM is - {}".format(eppm_plot[i]))
    ax.axis('equal')
    for j, a in enumerate(pie[2]):
        a.set_text("{}".format(eppm_pie_plot[j]))
    plt.legend(labels, bbox_to_anchor=(1.1,0.5))

#plt.axis('equal')
fig.suptitle("Temp")

plt.show()