删除图例matplotlib的颜色表示

时间:2019-10-24 14:24:24

标签: python matplotlib plot

我正在使用python和matplotlib库来比较两种算法。

我想知道如何除去图例中GA和PSO除外的图例中线条的颜色表示。

是否可以这样做以仅将文字保留在图例中?

这是我的情节:plot image

这是我的代码:

plt.plot(resultGA[0].n_evals, resultGA[0].x_f_vals)
plt.plot(resultPSO[0].n_evals, resultPSO[0].x_f_vals)
plt.plot(0, 0)
plt.plot(0, 0)
plt.plot(0, 0)
plt.plot(0, 0)
plt.plot(0, 0)
plt.plot(0, 0)
plt.xlabel("Número de gerações")
plt.ylabel("Fitness")
plt.title("Gráfico de convergência")

plt.legend(
    [
        "GA",
        "PSO",
        "Melhor valor(GA): " + str(round(minorValueGA, 4)),
        "Melhor valor(PSO): " + str(round(minorValuePSO, 4)),
        "Tempo GA(ms): " + str(round(benchmarkTimeGA, 4)),
        "Tempo PSO(ms): " + str(round(benchmarkTimePSO, 4)),
        "Melhor Fitness(GA): " + str(round(resultGA[1], 4)),
        "Melhor Fitness(PSO): " + str(round(resultPSO[1], 4)),
    ],
    loc="top left",
)

plt.show()

谢谢。

0 个答案:

没有答案
相关问题