Python processes csv data and dynamically displays the curve instance code, pythoncsv

Source: Internet
Author: User

Python processes csv data and dynamically displays the curve instance code, pythoncsv

This article mainly deals with the python processing of csv Data Dynamic Display curves and shares the implementation code as follows.

Code:

#-*-Coding: UTF-8-*-"Spyder Editor This temporary script file is located here: C: \ Users \ user \. spyder2 \. temp. py "Show how to modify the coordinate formatter to report the image" z "value of the nearest pixel given x and y" # coding: UTF-8 import time import string import OS import math import pylab import numpy as np from numpy import genfromtxt import matplotlib as mpl from matplotlib. colors import LogNorm from matplotlib. mlab import bivariate_normal import matplotlib. pyplot as plt import matplotlib. cm as cm import matplotlib. animation as animation metric = genfromtxt ('d: \ export.csv ', delimiter =', ') lines = len (metric) # print len (metric) # print len (metric [4]) # print metric [4] rowdatas = metric [:, 0] for index in range (len (metric [4])-1 ): a = metric [:, index + 1] rowdatas = np. row_stack (rowdatas, a) # print len (rowdatas [4]) # print rowdatas [4] # plt. figure (figsize = (38,38), dpi = 80) # plt. plot (rowdatas [4]) # plt. xlabel ('time') # plt. ylabel ('value') # plt. title ("USBHID data analysis") # plt. show () linenum = 1 ## if the parameter is list, one element in the list is retrieved by default, that is, metric [0], metric [1],... listdata = rowdatas. tolist () print listdata [4] # fig = plt. figure () # window = fig. add_subplot (111) # line, = window. plot (listdata [4]) fig, ax = plt. subplots () line, = ax. plot (listdata [4], lw = 2) ax. grid () time_template = 'data ROW = % d' time_text = ax. text (0.05, 0.9, '', transform = ax. transAxes) # ax = plt. axes (xlim = (0,700), ylim = (0,255) # line, = ax. plot ([], [], lw = 2) def update (data): global linenum line. set_ydata (data) # print 'this is line: % d' % linenum time_text.set_text (time_template % (linenum )) linenum = linenum + 1 # nextitem = input (U' input any character to continue: ') return line, def init (): # ax. set_ylim (0, 1.1) # ax. set_xlim (0, 10) # line. set_data (xdata) plt. xlabel ('time') plt. ylabel ('time') plt. title ('usbhid Data analytic') return line, ani = animation. funcAnimation (fig, update, listdata, interval = 1*1000, init_func = init, repeat = False) plt. show ()

Summary

The above is all about the sample code for processing csv data in python and dynamically displaying curves. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.