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

Plot two columns for 1000 rows with different color

I have two features datetime and volt for 1000 machineIDs. I am printing datetime and volt using matplotlib. Now, some machineIDs have unique values like there are 6-7 unique lines and hence there are multiple lines on the graph. Like this,

enter image description here

I want to segregate these lines in different colors for different machineIDs. Problem is I am plotting for datetime and volt only . So how do I do this?

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

Here is a sample data

machineID   dt_truncated    volt_rollingmean_12   label_e
964      2015-01-27 12:00:00    194.788225          1

Here I am plotting b/w volt and dt_truncated based on value of label_e. If label_e is1, then we consider it for plot. But there are 1000 machine IDs and because of that there are 6-7 different lines on plot.

As per the answer by quest I am getting this plot

enter image description here

>Solution :

Here is how you can go about it:

fig, ax = plt.subplots()
groups = df.groupby('machineID')
for name, group in groups:
    group = group.sort_values("dt_truncated")
    ax.plot(group.dt_truncated, group.volt_rollingmean_12, marker='o',  ms=12, label="machineID")

Here is the output
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