Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading