I have a csv file having following format Sample csv data
I need to plot graph for individual container CPUPerc, Memusage etc. against time stamp (time will be in x axis, CPU, memory value will be in Y axis) and once all the graphs generated, it should save all the graphs in a pdf file. I am able to generate all the graph with the following code, but when save it in pdf, it overwrites and saves only the last graph and not all. Can anyone help here.
Code is a below:
import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv('stats.csv')
mydict=["CPUPerc","MemUsage","NetIO","BlockIO","MemPerc"]
mp= df.groupby(['Container'])
for key,values in mp:
m=mp.get_group(key)
print key
for j in mydict:
y=m[j]
z=[]
for i in y:
if ( j=="CPUPerc" or j=="MemPerc"):
i=i.replace('%','')
z.append(i)
else:
i,sep,tail = i.partition(' ')
z.append(i)
y=map(float,list(z))
p=[]
print y
t=list()
for i in xrange(len(y)):
t.append(i)
plt.plot(t,y)
fig = plt.gcf()
plt.xticks(rotation=45)
ylab=('All {0} values for {1}------>'.format(j,key))
plt.xlabel('Time Series ------->')
plt.ylabel(ylab)
#plt.grid(True)
plt.grid(alpha=0.4)
plt.tight_layout()
plt.show()
fig.savefig("All_Graph.pdf")