Unable to plot graph using matplotlib

Posted by Aman Deep Gautam on Stack Overflow See other posts from Stack Overflow or by Aman Deep Gautam
Published on 2012-11-10T22:46:49Z Indexed on 2012/11/10 23:00 UTC
Read the original article Hit count: 189

Filed under:
|

I have the following code which searches all the directory in the current directory and then takes data from those files to plot the graph. The data is read correctly as verified by printing but there are no points plotted on graph.

import argparse
import os
import matplotlib.pyplot as plt

#find the present working directory
pwd=os.path.dirname(os.path.abspath(__file__))

#find all the folders in the present working directory.
dirs = [f for f in os.listdir('.') if os.path.isdir(f)]

plt.figure()
plt.xlim(0, 20000)
plt.ylim(0, 1)

for directory in dirs:
        os.chdir(os.path.join(pwd, directory));
        chd_dir = os.path.dirname(os.path.abspath(__file__))
        files = [ fl for fl in os.listdir('.') if os.path.isfile(fl) ]
        print files
        for f in files:
                f_obj = open(os.path.join(chd_dir, f), 'r')
                list_x = []
                list_y = []
                for i in xrange(0,4):
                        f_obj.next()
                for line in f_obj:
                        temp_list = line.split()
                        print temp_list
                        list_y.append(temp_list[0])
                        list_x.append(temp_list[1])
                print 'final_lsit'
                print list_x
                print list_y
                plt.plot(list_x, list_y, 'r.')
                f_obj.close()
os.chdir(pwd)
plt.savefig("test.jpg")

The input files look like the following:

5

865     14709   15573

14709           1.32667e-06
664             0.815601
14719           1.55333e-06
674             0.813277
14729           1.82667e-06
684             0.810185
14739           1.4e-06
694             0.808459

Can anybody help me with why this is happening? Being new I would like to know some tutorial where I can get help with kind of plotting as the tutorial I was following made me end up here.

Any help appreciated.

© Stack Overflow or respective owner

Related posts about python

Related posts about matplotlib