如何在matplotlib中对不同的直线给予不同的颜色

ttisahbt  于 2023-03-13  发布在  其他
关注(0)|答案(1)|浏览(120)
materias = ["MAT 1","MAT 2","MAT 3","FIS 1","FIS 2","FIS 3","QUI 1","QUI 2","GEO 1","GEO 2","PORT","RED","LIT","ART","ING","HIST 1","HIST 2","FIL","SOC","EDF","BIO 1","BIO 2","BIO 3"
]
for i in materias:
    
    note= str(i)
    file_name = 'images/' + str(i) +'.png'
    print(i,":")
    plt.plot(df["PROVAS"], df[i], label=note)
    plt.legend()
    plt.savefig(file_name)
    plt.show()

我不知道如何合并所有这些图表,也不知道如何给予它们不同的颜色(以更好的可视化)(抱歉我的英语不好)

a6b3iqyw

a6b3iqyw1#

只需将c=(R, G, B)添加到plot()调用中,其中RGB是介于0和1之间的值。
例如,

colors = [(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)]
plt.plot(df["PROVAS"], df[i], c=colors[2], label=note)

将使线变为绿色。对于您的示例,您可以跟踪索引,并在浏览材料列表时浏览颜色列表。

相关问题