#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2

    Plotting graph csv file


    Dear all,

    i have csv file , i wanted to plot the graph for this csv file.
    Actual format. here they get separated by row.
    Code:
    date	time	v1	 v2
    			
    16/3/2013	11.36.52	14.97	0
    			
    16/3/2013	11.37.0	20.96	0
    			
    16/3/2013	11.37.9	26.94	0
    			
    16/3/2013	11.37.17	32.93	0
    			
    16/3/2013	11.37.25	38.92	0
    			
    16/3/2013	11.37.34	44.91	0
    			
    16/3/2013	11.37.42	45	0
    			
    16/3/2013	11.37.50	45	0
    			
    16/3/2013	11.37.59	45	0
    			
    16/3/2013	11.38.7	45	0
    			
    16/3/2013	11.38.15	45	0
    			
    16/3/2013	11.38.24	45	0
    			
    16/3/2013	11.38.32	45	0
    Code:
    date	time	v1	 v2	time	hour	min	sec	time calc
    16/3/2013	11.36.52	14.97	0	11.36.52	11	36	52	41812
    16/3/2013	11.37.0	20.96	0	11.37.0	11	37	0	41820
    16/3/2013	11.37.9	26.94	0	11.37.9	11	37	9	41829
    16/3/2013	11.37.17	32.93	0	11.37.17	11	37	17	41837
    16/3/2013	11.37.25	38.92	0	11.37.25	11	37	25	41845
    16/3/2013	11.37.34	44.91	0	11.37.34	11	37	34	41854
    16/3/2013	11.37.42	45	0	11.37.42	11	37	42	41862
    16/3/2013	11.37.50	45	0	11.37.50	11	37	50	41870
    16/3/2013	11.37.59	45	0	11.37.59	11	37	59	41879
    16/3/2013	11.38.7	45	0	11.38.7	11	38	7	41887
    16/3/2013	11.38.15	45	0	11.38.15	11	38	15	41895
    16/3/2013	11.38.24	45	0	11.38.24	11	38	24	41904
    16/3/2013	11.38.32	45	0	11.38.32	11	38	32	41912
    i wanna convert this fromat

    and plot the graph for time vs v1
    and time vs v2
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,895
    Rep Power
    481
    Code:
    import gnuplot
    
    FILE_NAME_OF_INPUT_TSV = 'a'
    
    with open(FILE_NAME_OF_INPUT_TSV) as inf:
        DATA = inf.readlines()
    
    SECONDS = []
    V1 = []
    V2 = []
    
    for L in DATA:
        if '/' in L:
            FIELDS = L.split()
            TIME = FIELDS[1]
            (H,M,S,) = map(int,TIME.split('.'))
            SECONDS.append(S+60*(M+(60*(H))))
            V1.append(float(FIELDS[2]))
            V2.append(float(FIELDS[3]))
    
    gnuplot.xyxy(zip(SECONDS,V1),zip(SECONDS,V2))
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2
    please let me know how can i upload files here like zip, excel, pdf format. so clear the idea



    Originally Posted by b49P23TIvg
    Code:
    import gnuplot
    
    FILE_NAME_OF_INPUT_TSV = 'a'
    
    with open(FILE_NAME_OF_INPUT_TSV) as inf:
        DATA = inf.readlines()
    
    SECONDS = []
    V1 = []
    V2 = []
    
    for L in DATA:
        if '/' in L:
            FIELDS = L.split()
            TIME = FIELDS[1]
            (H,M,S,) = map(int,TIME.split('.'))
            SECONDS.append(S+60*(M+(60*(H))))
            V1.append(float(FIELDS[2]))
            V2.append(float(FIELDS[3]))
    
    gnuplot.xyxy(zip(SECONDS,V1),zip(SECONDS,V2))
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,895
    Rep Power
    481
    To upload files use the "manage attachments" button found in the "Additional Options" section below the forum post edit window.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2
    i can t able to mind manage attachments" button found in the "Additional Options"

    can you able share snapshot



    Originally Posted by b49P23TIvg
    To upload files use the "manage attachments" button found in the "Additional Options" section below the forum post edit window.
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,895
    Rep Power
    481
    You might not have been with devshed long enough to have a manage attachments option. I had thought that with more than 20 posts you'd be affirmed, but I don't actually know the rule. See attachment.
    Attached Images
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2
    here i am posted my code.

    here i wanna copy the time to excel sheet and calculate time
    Ts=(3600*h)+(60*m)+s

    and plot graph for Ts .if u compile in python u find whenever it write in to csv file it leave single row blank. How to remove it at intial stage itself..

    please correct code









    Code:
    import csv
    import os
    import time
    import sys
    import string
    from threading import Timer
    
    
    
    def main():
        pass
    
    if __name__ == '__main__':
        main()
        COUNT=0
    
        f=open("test.csv","w+");
        #result = csv.writer(f,delimiter=',')
        result = csv.writer(f,delimiter=',', dialect='excel-tab')
        result_statement=("MODE_STATUS","Dir","ACTUATOR_ON_OFF","MODE","DATE","TIME"," TRACKER DESIRED ANGLE"," TRACKER ACTUAL ANGLE","RESET_FLAG")
        result.writerow(result_statement)
        f.close()
    
    
        while COUNT<=3:
        #while():
          time.sleep(6)
          #ser=serial.Serial()
          #ser.port=12
          #ser.baudrate=9600
          #ser.open()
    
          str=("MODE STATUS:Track\r\ncalc dir: FWD\r\nActuator On/OFF:0\r\nMode:1\r\nLocal Date & Time:16/3/2013:.16.40.35\r\nTracker Desired Angle:-29.99\r\nTracker Actual Pos:-27.63\r\nRTC reset count is:0\r\n------------\r\n")
         # print "string are:\n",str
    
          #val1=string.rsplit(str,".")
    
          #print "val1 is:\n",val1
    
    
          val=str.split(":")
          print "value is:\n",val
          val1=str.split(".")
          print "val1 is:\n",val1
    
          lines=str.split("\r\n")
          print  "line statement are :\n",lines
          COUNT=COUNT+1
          #print COUNT
    
          f1=open("new.csv","a+");
          result = csv.writer(f1,delimiter=',')
          tst=[]
          for line in lines[:-1]:
            time1=line.split(".")
            for p in time1[1:]:
                    tst.append(p)
                    print tst.__imul__(3600)
          result.writerow(tst)
          f1.close()
    
    
    
          f=open("test.csv","a+");
        #  result = csv.writer(f,delimiter=',')
          result = csv.writer(f,delimiter=',', dialect='excel-tab')
          wst=[]
          for line in lines[:-1]:
                parts=line.split(":")
                for p in parts[1:]:
                    wst.append(p)
    
    
                #result = csv.writer(f,delimiter=',')
                #wst.append(parts[1:])
    
          #print "wst:\n",wst
    
          result.writerow(wst)
          f.close()
    
    
    
    
                #print parts
                #f=open("new.csv","a+");
                #result = csv.writer(f,delimiter=',')
    
                #print result_statement
                #f.write("%s," % ":".join(parts[1:])
    f.close()
    #ser.close()








    Originally Posted by b49P23TIvg
    To upload files use the "manage attachments" button found in the "Additional Options" section below the forum post edit window.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2
    Here i am attaching the file for which i need to plot graph/
    Here i have plotted using excel.How can write python code for above . data remain unchanged.
    i am using matplot library for python.
    Attached Files
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2
    Originally Posted by ajit.nayak87
    Dear all,

    i have csv file , i wanted to plot the graph for this csv file.
    Actual format. here they get separated by row.
    Code:
    date	time	v1	 v2
    			
    16/3/2013	11.36.52	14.97	0
    			
    16/3/2013	11.37.0	20.96	0
    			
    16/3/2013	11.37.9	26.94	0
    			
    16/3/2013	11.37.17	32.93	0
    			
    16/3/2013	11.37.25	38.92	0
    			
    16/3/2013	11.37.34	44.91	0
    			
    16/3/2013	11.37.42	45	0
    			
    16/3/2013	11.37.50	45	0
    			
    16/3/2013	11.37.59	45	0
    			
    16/3/2013	11.38.7	45	0
    			
    16/3/2013	11.38.15	45	0
    			
    16/3/2013	11.38.24	45	0
    			
    16/3/2013	11.38.32	45	0
    Code:
    date	time	v1	 v2	time	hour	min	sec	time calc
    16/3/2013	11.36.52	14.97	0	11.36.52	11	36	52	41812
    16/3/2013	11.37.0	20.96	0	11.37.0	11	37	0	41820
    16/3/2013	11.37.9	26.94	0	11.37.9	11	37	9	41829
    16/3/2013	11.37.17	32.93	0	11.37.17	11	37	17	41837
    16/3/2013	11.37.25	38.92	0	11.37.25	11	37	25	41845
    16/3/2013	11.37.34	44.91	0	11.37.34	11	37	34	41854
    16/3/2013	11.37.42	45	0	11.37.42	11	37	42	41862
    16/3/2013	11.37.50	45	0	11.37.50	11	37	50	41870
    16/3/2013	11.37.59	45	0	11.37.59	11	37	59	41879
    16/3/2013	11.38.7	45	0	11.38.7	11	38	7	41887
    16/3/2013	11.38.15	45	0	11.38.15	11	38	15	41895
    16/3/2013	11.38.24	45	0	11.38.24	11	38	24	41904
    16/3/2013	11.38.32	45	0	11.38.32	11	38	32	41912
    i wanna convert this fromat

    and plot the graph for time vs v1
    and time vs v2
    can some one help me for coding
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2

    NEED help in editing


    data look like thsi format . they are in csv file. I wanna take data from particular column and plot graph for that. how can do that using python.
    using matplot library in python



    Originally Posted by b49P23TIvg
    To upload files use the "manage attachments" button found in the "Additional Options" section below the forum post edit window.
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo