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 plot a line and dots on it using 2 lists in matplotlib?

I have 2 lists:

losses = [12,13,15,10,9,8]
dots = [1,0,0,1,0,0]

How can I plot the main line from the losses list, and wherever there’s a 1 in the dots list have a dot on that line?

I currently have something like this (note that it’s 2 different lists from the above example so the values are a bit different)

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

plt.plot(losses, c = 'b')
plt.plot(dots, c='r');

But I’m not sure how to make only dots on the main line

enter image description here

>Solution :

what about using a suitable marker?

from matplotlib import pyplot as plt

losses = [12,13,15,10,9,8]
dots = [1,0,0,1,0,0]

# value from losses whenever corresponding dots value is 1:
d = [v if d else None for d, v in zip(dots, losses)]

plt.plot(losses, c='b')
plt.plot(d, c='b', marker='|', markersize=40)

enter image description here

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