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