1

I am trying to read one input file of below format. Where Col[1] is x axis and Col[2] is y axis and col[3] is some name. I need to plot multiple line graphs for separate names of col[3]. Eg: Name sd with x,y values will have one line graph and name gg with relative x,y values will have another line graph. All in one output image but separate graphs. Is it possible with Python Matplotlib ? Pls do redirect me to any example. I have already checked couldn't find any.

akdj 12:00 34515 sd
sgqv 13:00 34626 sd
dfbb 13:00 14215 gg
ajdf 13:30 14224 gg
dsfb 13:45 25672 FW 
sfhh 14:00 85597 ad

Thanks for valuable suggestions

0

1 Answer 1

1

You can use the condition z=='some tag' to index the x and y array

Here's an example (based on the code in your previous question) that should do it. Use a set to automate the creation of tags:

import csv
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt

threshold = 30000
x,y,z = [],[],[]
csv_reader = csv.reader(open('input.csv'))

for line in csv_reader:
    y.append(int(line[2]))
    x.append(dt.datetime.strptime(line[1],'%H:%M'))
    z.append(line[3])

x=np.array(x)
y=np.array(y)

tags = list(set(z))
z=np.array(z)

fig=plt.figure()

for tag in tags:
    plt.plot(x[z==tag],y[z==tag],'o-',label=tag)

fig.autofmt_xdate()

plt.legend(loc=2)

plt.savefig('test.png')

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Tom .. Thank you again .. But ss or gd were only examples.. the input files will have many such rows. Of-course we cannot mention all of them as list. Is thr any option to automatically identify?
And I guess you understood well ..my intention is to merge the two and also annotate with something like this .. The names like ss gd are to be annotated on marker stackoverflow.com/questions/5147112/…
you could use a python set to get all the unique tags in your file. For example list(set(z)) above would return ['sd','gg','FW','ad']. Then, you could loop over that new list, and create a condition for each one. I've edited the answer to do just this.
You are just wow .. if you can please help me with this one also stackoverflow.com/questions/30832216/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.