Search code examples
pythondataframematplotlibgraphlabel

How to give diferent colors to diferent lines in matplotlib


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

i dont know how to merge all of these graphs and dont know either how to give them different colors (to better visualisation) (sorry for my bad english)


Solution

  • just add c=(R, G, B) to the plot() call, where R, G, and B are values between 0 and 1.

    For example,

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

    will make the line green. For your example, you could keep track of an index and step through the list of colors as you advance through the list of materials.